agentix-cli 0.2.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/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
package/dist/cli.js ADDED
@@ -0,0 +1,157 @@
1
+ #!/usr/bin/env node
2
+ import{I as He,J as u,K as oe,a as Me,b as De,c as pe,d as Ne,g as Oe,h as Fe,i as z,n as Le,s as Ue,t as _e}from"./chunk-THMHQELC.js";import"./chunk-6PVFYFUE.js";import{D as te,E as je,F as de,b as ce,c as Ce,e as Ae,l as V,m as _,o as ee,r as Ee,s as x,x as H,y as Re}from"./chunk-NZ6W33BD.js";import{d as Pe}from"./chunk-FRFR27IN.js";import{a as Se,b as Ie}from"./chunk-SFQUP3BP.js";import{a as t,b as X,e as Te,f as Z,m as U}from"./chunk-FUYKPFUV.js";import{existsSync as lt}from"fs";import ct from"path";import{Command as dt}from"commander";import Ke from"chalk";var Ge=new dt().name("chat").description("start an interactive AI coding session").option("--resume","resume the last session",!1).option("-s, --session <id>","resume a specific session").option("--list","list saved sessions",!1).option("-p, --provider <provider>","AI provider (claude-code, claude)","claude-code").option("-m, --model <model>","model to use").option("--api-key <key>","API key for the provider").option("-c, --cwd <cwd>","working directory",process.cwd()).option("--debug","enable debug mode with verbose logging",!1).option("--mode <mode>","permission mode (default, acceptEdits, plan, yolo)","yolo").action(async o=>{try{if(o.list){let i=Le();if(!i.length){t.info("No saved sessions");return}console.log(),console.log(Ke.bold(" Saved sessions:")),console.log();for(let s of i.slice(0,20)){let d=new Date(s.updatedAt).toLocaleDateString(),p=s.messages.length,f=s.tokensUsed.toLocaleString();console.log(` ${Ke.cyan(s.id)} ${d} ${p} msgs ${f} tokens`)}console.log();return}o.debug&&_(!0),o.mode&&H.setMode(o.mode);let e=ct.resolve(o.cwd);lt(e)||(t.error(`The path ${e} does not exist.`),process.exit(1));let n=await oe();await new Ue({cwd:e,provider:o.provider,model:o.model,apiKey:o.apiKey,resume:o.resume,sessionId:o.session,version:n.version||"1.0.0"}).start()}catch(e){u(e)}});import{existsSync as gt}from"fs";import ut from"path";import E from"chalk";import{Command as ht}from"commander";import wt from"ora";import ge from"prompts";import{z as T}from"zod";import h from"chalk";function O(){return Date.now()}function me(o){let e=Math.floor(o/1e3),n=Math.floor(e/60),r=Math.floor(n/60),i=String(e%60).padStart(2,"0"),s=String(n%60).padStart(2,"0");return r>0?`${r}:${s}:${i}`:`${n}:${i}`}function pt(o,e){let n=o.replace(/\r\n/g,`
3
+ `).split(`
4
+ `);return n.length<=e?n:n.slice(n.length-e)}function mt(o,e){return o.length<=e?o:o.slice(o.length-e)}var J=class{constructor(e){this.opts=e;this.outputType=e.outputType||"auto",this.maxSteps=e.maxSteps}startedAt=O();phase="Analyzing project";outputType="auto";iteration=0;maxSteps;filesCreated=0;filesWritten=0;filesSkipped=0;filesErrors=0;eventLog=[];textTail="";lastActivityAt=O();dirty=!0;renderTimer;pulseTimer;stopped=!1;restoreHandlersInstalled=!1;handleExit=()=>this.stop();handleSigint=()=>{this.stop(),process.exit(130)};handleSigterm=()=>{this.stop(),process.exit(143)};start(){process.stdout.isTTY&&(process.stdout.write("\x1B[?25l"),this.installRestoreHandlers(),this.pulseTimer=setInterval(()=>{this.stopped||this.scheduleRender()},120),this.render())}stop(){this.stopped||(this.stopped=!0,this.renderTimer&&clearTimeout(this.renderTimer),this.renderTimer=void 0,this.pulseTimer&&clearInterval(this.pulseTimer),this.pulseTimer=void 0,process.stdout.isTTY&&(process.stdout.write("\x1B[?25h"),process.stdout.write(`
5
+ `)),this.uninstallRestoreHandlers())}onEvent(e){if(!this.stopped){if(this.lastActivityAt=O(),e.type==="context_ready")this.phase="Generating",this.outputType=e.outputType,this.log(`Context ready. Output type: ${e.outputType}`);else if(e.type==="iteration")this.phase="Generating",this.iteration=e.iteration,this.log(`Step ${e.iteration}${this.maxSteps?`/${this.maxSteps}`:""}`);else if(e.type==="tool_call")this.phase="Running tools",this.log(`Tool: ${e.name} (${e.id})`);else if(e.type==="tool_result"){let n=e.is_error?h.red("error"):h.green("ok");this.log(`Tool result: ${e.name} (${e.id}) ${n}`)}else e.type==="step_complete"?(this.filesCreated+=e.filesCount,this.log(`Created ${e.filesCount} file(s)`)):e.type==="text_delta"?this.textTail=mt(this.textTail+e.text,4e3):e.type==="done"?(this.phase="Writing files",this.log("Model completed. Writing files...")):e.type==="generate_result"?(this.phase="Done",this.filesWritten=e.result.files.written.length,this.filesSkipped=e.result.files.skipped.length,this.filesErrors=e.result.files.errors.length,e.result.healResult&&this.log(e.result.healResult.healed?"Verification: ok":"Verification: failed"),e.result.followUp&&(this.phase="Needs input",this.log("Waiting for your answer..."))):e.type==="error"&&(this.phase="Error",this.log(h.red(e.error)));this.scheduleRender()}}log(e){let n=me(O()-this.startedAt),r=`${h.dim(n)} ${e}`;this.eventLog.push(r),this.eventLog.length>25&&(this.eventLog=this.eventLog.slice(this.eventLog.length-25))}scheduleRender(){process.stdout.isTTY&&(this.dirty=!0,!this.renderTimer&&(this.renderTimer=setTimeout(()=>{this.renderTimer=void 0,this.render()},50)))}render(){if(!process.stdout.isTTY||!this.dirty)return;this.dirty=!1;let e=process.stdout.columns||80,n=process.stdout.rows||24,r=["|","/","-","\\"],i=r[Math.floor((O()-this.startedAt)/120)%r.length],s=O()-this.lastActivityAt,d=h.bold("agentx generate")+h.dim(` ${me(O()-this.startedAt)}`),p=`${h.dim("Task:")} ${this.opts.task}`,f=`${h.dim("Provider:")} ${this.opts.provider}`+(this.opts.model?` ${h.dim("Model:")} ${this.opts.model}`:"")+` ${h.dim("Type:")} ${this.outputType}`,g=`${h.dim("CWD:")} ${this.opts.cwd}`+(this.opts.outputDir?` ${h.dim("Out:")} ${this.opts.outputDir}`:"")+(this.opts.overwrite?` ${h.dim("Overwrite:")} yes`:"")+(this.opts.dryRun?` ${h.dim("Dry-run:")} yes`:""),a=`${h.dim("Status:")} ${h.bold(this.phase)} ${h.dim(i)}`+(this.iteration?` ${h.dim("Step:")} ${this.iteration}${this.maxSteps?`/${this.maxSteps}`:""}`:"")+(s>1500?` ${h.dim("Idle:")} ${me(s)}`:"")+(this.filesWritten||this.filesSkipped||this.filesErrors?` ${h.dim("Files:")} ${h.green(String(this.filesWritten))} written, ${h.yellow(String(this.filesSkipped))} skipped, ${h.red(String(this.filesErrors))} failed`:this.filesCreated?` ${h.dim("Files:")} ${this.filesCreated} created`:""),m=h.dim("".padEnd(Math.min(e,80),"\u2500")),R=Math.max(0,n-6),j=Math.max(6,Math.floor(R*.55)),N=Math.max(4,R-j),M=this.eventLog.slice(-N),Q=pt(this.textTail,j),ae=[d,p,f,g,a,m,h.dim("Events:"),...M.map(D=>D.slice(0,e)),m,h.dim("Output (tail):"),...Q.map(D=>D.slice(0,e))].join(`
6
+ `);process.stdout.write("\x1B[H\x1B[2J"),process.stdout.write(ae)}installRestoreHandlers(){this.restoreHandlersInstalled||(this.restoreHandlersInstalled=!0,process.once("exit",this.handleExit),process.once("SIGINT",this.handleSigint),process.once("SIGTERM",this.handleSigterm))}uninstallRestoreHandlers(){this.restoreHandlersInstalled&&(this.restoreHandlersInstalled=!1,process.off("exit",this.handleExit),process.off("SIGINT",this.handleSigint),process.off("SIGTERM",this.handleSigterm))}};import I from"chalk";function ft(o,e){return o.replace(/\r\n/g,`
7
+ `).split(`
8
+ `).map(n=>n.length?e+n:n).join(`
9
+ `)}function fe(o){return o=o.replace(/`([^`]+)`/g,(e,n)=>I.cyan(n)),o=o.replace(/\[([^\]]+)\]\(([^)]+)\)/g,(e,n,r)=>`${n} ${I.dim(`(${r})`)}`),o=o.replace(/\*\*([^*]+)\*\*/g,(e,n)=>I.bold(n)),o}function Be(o){let e=o.replace(/\r\n/g,`
10
+ `).split(`
11
+ `),n=[];for(let r of e){let i=r.trimEnd();if(/^\s*#{1,6}\s+/.test(i)){let s=i.replace(/^\s*#{1,6}\s+/,"");n.push(I.bold(fe(s)));continue}if(/^\s*([-*_]\s*){3,}$/.test(i)){n.push(I.dim("\u2500".repeat(40)));continue}if(/^\s*>\s?/.test(i)){n.push(I.dim("\u2502 ")+fe(i.replace(/^\s*>\s?/,"")));continue}n.push(fe(i))}return n.join(`
12
+ `)}function ie(o){let e=(o||"").replace(/\r\n/g,`
13
+ `);if(!e.trim())return"";let n=e.split(/```/g);if(n.length===1)return Be(e);let r=[];for(let i=0;i<n.length;i++){let s=n[i];if(!(i%2===1)){r.push(Be(s));continue}let p=s.indexOf(`
14
+ `),f=p===-1?s.trim():s.slice(0,p).trim(),g=p===-1?"":s.slice(p+1),a=f?I.dim("```"+f):I.dim("```"),m=I.dim("```"),w=I.dim(ft(g.replace(/\s+$/g,""),""));r.push([a,w,m].filter(Boolean).join(`
15
+ `))}return r.join(`
16
+ `).replace(/^\n+|\n+$/g,"")}var yt=T.object({task:T.string().optional(),type:T.string().default("auto"),output:T.string().optional(),overwrite:T.boolean().default(!1),dryRun:T.boolean().default(!1),provider:T.enum(["claude-code","claude","openai","ollama","custom"]).default("claude-code"),model:T.string().optional(),apiKey:T.string().optional(),cwd:T.string(),noContext7:T.boolean().default(!1),yes:T.boolean().default(!1)}),We=new ht().name("generate").aliases(["gen","g"]).description("generate anything using AI \u2014 components, pages, APIs, docs, skills, and more").argument("[task...]","describe what you want to generate").option("-t, --type <type>",`output type: ${ce.join(", ")}`,"auto").option("-o, --output <dir>","output directory").option("--overwrite","overwrite existing files",!1).option("--dry-run","preview without writing files",!1).option("-p, --provider <provider>","AI provider (claude-code, claude, openai, ollama)","claude-code").option("-m, --model <model>","model to use").option("--api-key <key>","API key for the provider").option("-c, --cwd <cwd>","working directory",process.cwd()).option("--no-context7","disable Context7 documentation lookup").option("--max-steps <n>","max agentic loop steps for complex generation (default: 5)","5").option("-y, --yes","skip confirmation prompts",!1).option("--debug","enable debug mode with verbose logging",!1).option("--no-tui","disable interactive TUI output").option("--mode <mode>","permission mode (default, acceptEdits, plan, yolo)","yolo").option("--heal","verify generated code and auto-fix errors").option("--no-heal","skip verification after generation").option("--test-cmd <cmd>","test command for heal verification").option("--build-cmd <cmd>","build command for heal verification").action(async(o,e)=>{try{let n=o?.length?o.join(" "):e.task;e.debug&&_(!0),e.mode&&H.setMode(e.mode);let r=ut.resolve(e.cwd);if(gt(r)||(t.error(`The path ${r} does not exist.`),process.exit(1)),!n){let m=await ge({type:"text",name:"task",message:"What would you like to generate?",validate:w=>w.trim()?!0:"Please describe what to generate"});m.task||(t.warn("No task provided. Exiting."),process.exit(0)),n=m.task}if(e.type==="auto"&&!e.yes){let{type:m}=await ge({type:"select",name:"type",message:"Output type (or auto-detect)",choices:[{title:"Auto-detect",value:"auto"},...ce.filter(w=>w!=="auto").map(w=>({title:`${w} \u2014 ${Ce[w]}`,value:w}))],initial:0});m!==void 0&&(e.type=m)}let i=yt.parse({task:n,...e,apiKey:e.apiKey,noContext7:!e.context7}),s=parseInt(e.maxSteps||"5",10),d=!!e.tui&&!!process.stdout.isTTY&&!e.debug,p=!d&&!e.debug?wt("Waiting for provider...").start():void 0,f=d?new J({task:n,provider:i.provider,model:i.model,cwd:r,outputDir:i.output,outputType:i.type,maxSteps:s,overwrite:i.overwrite,dryRun:i.dryRun}):void 0;d||(t.break(),t.info(`Task: ${E.bold(n)}`),t.info(`Provider: ${E.bold(i.provider)}`),i.type!=="auto"&&t.info(`Type: ${E.bold(i.type)}`),i.output&&t.info(`Output: ${E.bold(i.output)}`),i.dryRun&&t.warn("Dry run mode \u2014 no files will be written"),t.break()),f?.start();let g,a;for await(let m of de({task:n,outputType:i.type,outputDir:i.output,overwrite:i.overwrite,dryRun:i.dryRun,provider:i.provider,model:i.model,apiKey:i.apiKey,cwd:r,context7:!i.noContext7,interactive:!i.yes,maxSteps:s,heal:e.heal,healConfig:e.testCmd||e.buildCmd?{testCommand:e.testCmd,buildCommand:e.buildCmd}:void 0}))f?.onEvent(m),d||(m.type==="context_ready"&&p&&(p.text="Generating..."),m.type==="context_ready"?(t.info("Analyzing project... done"),t.info(`Output type: ${m.outputType}`)):m.type==="iteration"?t.info(`Step ${m.iteration}/${s}...`):m.type==="tool_call"?t.info(`Tool: ${m.name}`):m.type==="tool_result"?t.info(`Tool result: ${m.name}${m.is_error?" (error)":""}`):m.type==="error"&&t.error(m.error)),m.type==="generate_result"&&(g=m.result),m.type==="error"&&(a=m.error);if(p?.stop(),f?.stop(),a)throw new Error(a);if(!g)throw new Error("Generation finished without a result");if(g.followUp){if(t.break(),t.info(E.yellow("The agent needs more information:")),t.break(),g.content){let w=process.stdout.isTTY?ie(g.content):g.content;console.log(w),t.break()}console.log(process.stdout.isTTY?ie(g.followUp):g.followUp),t.break();let{answer:m}=await ge({type:"text",name:"answer",message:"Your answer:"});if(m){let w=`${n}
17
+
18
+ Previous agent output (for context):
19
+ ${g.content||""}
20
+
21
+ User response: ${m}
22
+
23
+ If the above was a plan awaiting approval and the user approved, proceed to implementation now using create_files (do not ask for approval again).`,R=d?new J({task:w,provider:i.provider,model:i.model,cwd:r,outputDir:i.output,outputType:i.type,maxSteps:s,overwrite:i.overwrite,dryRun:i.dryRun}):void 0;R?.start();let j,N;for await(let M of de({task:w,outputType:i.type,outputDir:i.output,overwrite:i.overwrite,dryRun:i.dryRun,provider:i.provider,model:i.model,apiKey:i.apiKey,cwd:r,context7:!i.noContext7,interactive:!1,maxSteps:s,heal:e.heal,healConfig:e.testCmd||e.buildCmd?{testCommand:e.testCmd,buildCommand:e.buildCmd}:void 0}))R?.onEvent(M),M.type==="generate_result"&&(j=M.result),M.type==="error"&&(N=M.error);if(R?.stop(),N)throw new Error(N);if(!j)throw new Error("Generation finished without a result");Ye(j)}}else Ye(g)}catch(n){u(n)}});function Ye(o){if(t.break(),o.content){let e=process.stdout.isTTY?ie(o.content):o.content;console.log(e),t.break()}if(o.files.written.length){t.success(`Created ${o.files.written.length} file(s):`);for(let e of o.files.written)console.log(` ${E.green("+")} ${e}`)}if(o.files.skipped.length){t.warn(`Skipped ${o.files.skipped.length} existing file(s):`);for(let e of o.files.skipped)console.log(` ${E.yellow("~")} ${e} (use --overwrite)`)}if(o.files.errors.length){t.error(`Failed ${o.files.errors.length} file(s):`);for(let e of o.files.errors)console.log(` ${E.red("x")} ${e}`)}if(o.healResult&&(t.break(),o.healResult.healed?o.healResult.attempts===0?t.success("Verification passed \u2014 generated code is clean"):t.success(`Auto-healed in ${o.healResult.attempts} attempt(s)`+(o.healResult.filesChanged?.length?` (fixed: ${o.healResult.filesChanged.join(", ")})`:"")):o.healResult.error&&(t.error(`Verification failed after ${o.healResult.attempts} attempt(s):`),console.log(E.dim(` ${o.healResult.error.split(`
24
+ `).slice(0,3).join(`
25
+ `)}`)))),o.tokensUsed){t.break();let e=V.getSummary();if(e.steps.length>1){t.info(`Tokens used: ${o.tokensUsed} across ${e.steps.length} steps`);for(let n of e.steps)t.info(` Step ${n.step}: ${(n.inputTokens+n.outputTokens).toLocaleString()} tokens ($${n.cost.toFixed(4)})`);t.info(` Total cost: $${e.totalCost.toFixed(4)}`)}else t.info(`Tokens used: ${o.tokensUsed} ($${e.totalCost.toFixed(4)})`)}}import{existsSync as kt,promises as ue}from"fs";import ne from"path";import v from"chalk";import{Command as bt}from"commander";import he from"ora";import we from"prompts";import vt from"fast-glob";var qe=new bt().name("evolve").aliases(["ev","transform"]).description("modify existing code using AI \u2014 add features, refactor, migrate patterns").argument("[task...]","describe the transformation to apply").option("-g, --glob <pattern>","glob pattern for files to evolve (e.g., src/components/**/*.tsx)").option("--max-files <n>","maximum number of files to process","10").option("-p, --provider <provider>","AI provider (claude-code, claude)","claude-code").option("-m, --model <model>","model to use").option("--api-key <key>","API key").option("-c, --cwd <cwd>","working directory",process.cwd()).option("--no-context7","disable Context7 doc lookup").option("-y, --yes","apply all changes without confirmation",!1).option("--dry-run","show proposed changes without writing",!1).option("--debug","enable debug mode with verbose logging",!1).option("--mode <mode>","permission mode (default, acceptEdits, plan, yolo)").option("--heal","verify generated code and auto-fix errors").option("--no-heal","skip verification after applying changes").option("--test-cmd <cmd>","test command for heal verification").option("--build-cmd <cmd>","build command for heal verification").action(async(o,e)=>{try{let n=o?.length?o.join(" "):void 0,r=ne.resolve(e.cwd);if(kt(r)||(t.error(`The path ${r} does not exist.`),process.exit(1)),e.debug&&_(!0),e.mode&&H.setMode(e.mode),!n){let l=await we({type:"text",name:"task",message:"Describe the transformation to apply:",validate:y=>y.trim()?!0:"Please describe the transformation"});l.task||(t.warn("No task provided. Exiting."),process.exit(0)),n=l.task}let i=n;if(x.has("pre:prompt")){let l=await x.execute("pre:prompt",{event:"pre:prompt",task:i,cwd:r});l.blocked&&(t.error(l.message||"Blocked by pre:prompt hook"),process.exit(1)),l.modified?.task&&(i=String(l.modified.task))}if(x.has("pre:generate")){let l=await x.execute("pre:generate",{event:"pre:generate",task:i,cwd:r});l.blocked&&(t.error(l.message||"Blocked by pre:generate hook"),process.exit(1))}let s=e.glob;if(!s){let l=await we({type:"text",name:"glob",message:"File pattern to evolve (glob):",initial:"src/**/*.{ts,tsx,js,jsx}",validate:y=>y.trim()?!0:"Pattern is required"});l.glob||(t.warn("No pattern provided. Exiting."),process.exit(0)),s=l.glob}let d=await vt.glob(s,{cwd:r,ignore:["**/node_modules/**","**/dist/**","**/build/**","**/.next/**","**/target/**","**/.git/**"],onlyFiles:!0}),p=parseInt(e.maxFiles,10);d.length||(t.warn(`No files matched pattern: ${s}`),process.exit(0));let f=d.slice(0,p);d.length>p&&t.warn(`Found ${d.length} files, processing first ${p}. Use --max-files to increase.`),t.break(),t.info(`Task: ${v.bold(i)}`),t.info(`Files: ${v.bold(String(f.length))} matching ${v.dim(s)}`),t.break();let g=he("Reading files and analyzing project...").start(),a=[];for(let l of f){let y=ne.resolve(r,l),b=await ue.readFile(y,"utf8");a.push({path:l,content:b})}let m=await te(r,i,{provider:e.provider,context7:{enabled:e.context7!==!1}}),w=Pe(m.skills,i,void 0);w.length&&ee.context("skills",`${w.length} matched for evolve`),g.text="Generating transformations...";let R=$t(m,w.map(l=>l.skill)),j=a.map(l=>`## File: ${l.path}
26
+ \`\`\`
27
+ ${Ct(l.content,4e3)}
28
+ \`\`\``).join(`
29
+
30
+ `),N=`# Transformation Task
31
+ ${i}
32
+
33
+ # Files to Transform
34
+ ${j}
35
+
36
+ Transform these files according to the task. For each file that needs changes, use \`create_files\` with the complete updated file content. Only include files that actually need changes \u2014 skip files that don't need modification.`;await Z(e.apiKey)||(t.error("No credentials configured. Run `agentx model` to set up."),process.exit(1));let Q=e.provider,ae=U(Q,e.apiKey),D=e.model||X()?.model,rt=[{role:"system",content:R},{role:"user",content:N}];ee.step(1,`Starting evolve generation (model: ${D||"default"})`);let C=await ae.generate(rt,{model:D,maxTokens:16384}),le=C.tokensUsed||0,ve=D||"claude-sonnet-4-20250514",$e=Math.round(le*.3),st=le-$e;if(V.recordStep(1,ve,$e,st),ee.api("evolve",ve,le),g.stop(),C.followUp){t.break(),t.info(v.yellow("The agent needs more information:")),t.break(),console.log(C.followUp),t.break();return}if(!C.files.length){t.info("No changes proposed."),C.content&&(t.break(),console.log(C.content));return}let W=[];for(let l of C.files){let y=a.find(b=>b.path===l.path);W.push({path:l.path,original:y?.content||"",proposed:l.content,description:l.description})}t.break(),console.log(v.bold(` ${W.length} file(s) with proposed changes:`)),t.break(),C.content&&(console.log(v.dim(C.content)),t.break());let P=[];for(let l of W){console.log(v.bold.cyan(` ${l.path}`)),l.description&&console.log(v.dim(` ${l.description}`)),t.break();let y=xt(l.original,l.proposed);for(let b of y.slice(0,40))b.startsWith("+")?console.log(v.green(` ${b}`)):b.startsWith("-")?console.log(v.red(` ${b}`)):console.log(v.dim(` ${b}`));if(y.length>40&&console.log(v.dim(` ... ${y.length-40} more lines`)),t.break(),e.yes||e.dryRun)P.push(l);else{let{action:b}=await we({type:"select",name:"action",message:`${l.path}`,choices:[{title:"Accept",value:"accept"},{title:"Skip",value:"skip"},{title:"Accept all remaining",value:"accept-all"},{title:"Quit",value:"quit"}]});if(b==="accept")P.push(l);else if(b==="accept-all"){P.push(l);let S=W.slice(W.indexOf(l)+1);P.push(...S);break}else if(b==="quit")break}}if(!P.length){t.info("No changes applied.");return}if(e.dryRun){t.break(),t.success(`Dry run: ${P.length} file(s) would be modified:`);for(let l of P)console.log(` ${v.green("~")} ${l.path}`);return}let at=he("Applying changes...").start(),xe=0,L=0,q=[];for(let l of P){if(x.has("pre:file-write")){let y=await x.execute("pre:file-write",{event:"pre:file-write",file:l.path,fileContent:l.proposed,cwd:r});if(y.blocked){t.warn(`Skipped ${l.path}: ${y.message||"blocked by hook"}`);continue}}try{let y=ne.resolve(r,l.path),b=ne.dirname(y);await ue.mkdir(b,{recursive:!0}),await ue.writeFile(y,l.proposed,"utf8"),xe++,q.push(l.path),x.has("post:file-write")&&await x.execute("post:file-write",{event:"post:file-write",file:l.path,cwd:r})}catch(y){t.error(`Failed to write ${l.path}: ${y.message}`),L++}}at.stop(),t.break(),t.success(`Applied ${xe} change(s):`);for(let l of P)q.includes(l.path)&&console.log(` ${v.green("~")} ${l.path}`);L&&t.error(`${L} file(s) failed to write.`);try{let l=new Re(r);await l.load(),await l.recordGeneration({type:"evolution",task:i,files:q,success:L===0,error:L>0?`${L} file(s) failed to write`:void 0,context:{techStack:m.techStack.languages.map(String),frameworks:m.techStack.frameworks.map(String),skillsUsed:w.map(y=>y.skill.frontmatter.name)}})}catch{}if(e.heal!==!1&&q.length>0){let{HealEngine:l}=await import("./heal-MJLBETRV.js"),y=new l(r,{enabled:!0,testCommand:e.testCmd,buildCommand:e.buildCmd,maxAttempts:3,provider:Q,model:D,apiKey:e.apiKey}),b=he("Verifying changes...").start(),S=await y.detectAndHeal(q,i);b.stop(),S.healed?S.attempts===0?t.success("Verification passed \u2014 changes are clean"):t.success(`Auto-healed in ${S.attempts} attempt(s)`+(S.filesChanged.length?` (fixed: ${S.filesChanged.join(", ")})`:"")):S.error&&(t.error(`Verification failed after ${S.attempts} attempt(s):`),console.log(v.dim(` ${S.error.split(`
37
+ `).slice(0,3).join(`
38
+ `)}`)),await x.execute("on:error",{event:"on:error",error:new Error(S.error),task:i,cwd:r}))}if(x.has("post:generate")&&await x.execute("post:generate",{event:"post:generate",task:i,content:C.content,cwd:r}),C.tokensUsed){t.break();let l=V.getSummary();t.info(`Tokens used: ${C.tokensUsed} ($${l.totalCost.toFixed(4)})`)}}catch(n){u(n)}});function $t(o,e){let n=[];n.push(`You are agentx evolve, an agentic code transformation tool. You modify existing code according to user instructions.
39
+
40
+ Your primary tool is \`create_files\` \u2014 use it to output the COMPLETE updated content of each file that needs changes.
41
+ If the request is ambiguous, use \`ask_user\` to ask a clarifying question.
42
+
43
+ CRITICAL RULES:
44
+ - Output the FULL file content for each changed file (not just the diff)
45
+ - Keep the file path exactly as given \u2014 do not rename files unless explicitly asked
46
+ - Preserve existing code patterns, naming conventions, and style
47
+ - Only modify what's necessary for the transformation
48
+ - Do NOT remove unrelated code or comments
49
+ - Do NOT add unrelated features or "improvements"
50
+ - Include all existing imports \u2014 do not accidentally drop them
51
+ - If a file doesn't need changes, do NOT include it in the output`),n.push(`# Project Tech Stack
52
+ ${Ie(o.techStack)}`);let r=Object.keys(o.techStack.dependencies).slice(0,20);r.length&&n.push(`# Key Dependencies
53
+ ${r.join(", ")}`);let i=Ae(o.schemas);return i&&n.push(`# Project Schemas
54
+ ${i}`),e.length&&n.push(`# Active Skills
55
+ `+e.map(s=>`## ${s.frontmatter.name}
56
+ ${s.frontmatter.description}
57
+
58
+ ${s.instructions}`).join(`
59
+
60
+ ---
61
+
62
+ `)),o.docs&&n.push(o.docs),o.projectInstructions&&n.push(`# Project Instructions
63
+ ${o.projectInstructions}`),o.memoryContext&&n.push(o.memoryContext),n.join(`
64
+
65
+ `)}function xt(o,e){let n=o.split(`
66
+ `),r=e.split(`
67
+ `),i=[],s=Math.max(n.length,r.length),d=[],p=-10;for(let f=0;f<s;f++){let g=f<n.length?n[f]:void 0,a=f<r.length?r[f]:void 0;g===a?f-p<=2?i.push(` ${g}`):(d.push(` ${g}`),d.length>2&&d.shift()):(f-p>3&&i.length>0&&i.push(" ..."),i.push(...d),d=[],g!==void 0&&a!==void 0?(i.push(`-${g}`),i.push(`+${a}`)):g!==void 0?i.push(`-${g}`):a!==void 0&&i.push(`+${a}`),p=f)}return i}function Ct(o,e){return o.length<=e?o:o.slice(0,e)+`
68
+ // ... (truncated)`}import{existsSync as Tt,promises as St}from"fs";import Ve from"path";import $ from"chalk";import{Command as It}from"commander";import At from"ora";import re from"prompts";var K=[{name:"saas-starter",description:"Full-stack SaaS starter with auth, billing, dashboard, and landing page",prompt:`Create a full-stack SaaS starter project with:
69
+ 1. Authentication (sign up, sign in, forgot password, email verification)
70
+ 2. Billing integration with Stripe (pricing page, checkout, subscription management, webhooks)
71
+ 3. Dashboard with sidebar navigation, user profile, settings page
72
+ 4. Landing page with hero, features, pricing, testimonials, FAQ, footer
73
+ 5. Database schema for users, subscriptions, teams
74
+ 6. API routes for all CRUD operations
75
+ 7. Middleware for auth protection
76
+ 8. Environment variables template`,skills:[],outputType:"website",tags:["saas","auth","billing","stripe","dashboard"]},{name:"api-service",description:"REST API service with auth, validation, error handling, and tests",prompt:`Create a REST API service with:
77
+ 1. Project structure with routes, controllers, middleware, models, utils
78
+ 2. Authentication middleware (JWT)
79
+ 3. Input validation using the project's validation library
80
+ 4. Centralized error handling with proper HTTP status codes
81
+ 5. Health check endpoint
82
+ 6. CRUD endpoints for a sample resource
83
+ 7. Request logging middleware
84
+ 8. Rate limiting
85
+ 9. Environment configuration
86
+ 10. Test suite for all endpoints`,skills:[],outputType:"api",tags:["api","rest","backend","auth","jwt"]},{name:"cli-tool",description:"CLI application with commands, flags, interactive prompts, and config",prompt:`Create a CLI tool with:
87
+ 1. Command framework setup (commander or similar)
88
+ 2. Multiple subcommands with flags and arguments
89
+ 3. Interactive prompts for user input
90
+ 4. Configuration file support (read/write)
91
+ 5. Colored output and spinners
92
+ 6. Help text and version command
93
+ 7. Error handling with friendly messages
94
+ 8. A sample command that demonstrates all features`,skills:[],outputType:"script",tags:["cli","tool","command-line"]},{name:"component-library",description:"UI component library with Storybook, tests, and documentation",prompt:`Create a UI component library with:
95
+ 1. Button, Input, Card, Modal, Dropdown, Alert, Badge, Avatar components
96
+ 2. Consistent theming system (colors, typography, spacing)
97
+ 3. All components are accessible (ARIA, keyboard navigation)
98
+ 4. Component props are typed and documented
99
+ 5. Each component has unit tests
100
+ 6. Storybook stories for each component
101
+ 7. Export barrel file
102
+ 8. Package.json configured for publishing`,skills:[],outputType:"component",tags:["components","ui","library","storybook"]},{name:"fullstack-app",description:"Full-stack application with database, API, UI, and deployment config",prompt:`Create a full-stack application with:
103
+ 1. Database schema with models for a practical app (e.g., task management)
104
+ 2. API layer with CRUD operations for all models
105
+ 3. Frontend pages: home, list view, detail view, create/edit forms
106
+ 4. Authentication flow (login, register, protected routes)
107
+ 5. Form validation on client and server
108
+ 6. Loading states and error handling in the UI
109
+ 7. Docker configuration for development
110
+ 8. CI/CD workflow for GitHub Actions
111
+ 9. Environment configuration template`,skills:[],outputType:"website",tags:["fullstack","app","database","auth"]},{name:"mobile-app",description:"Mobile application with navigation, screens, and native features",prompt:`Create a mobile application with:
112
+ 1. Navigation setup (tab navigation + stack navigation)
113
+ 2. Screens: Home, Profile, Settings, List, Detail
114
+ 3. Authentication flow (login, register)
115
+ 4. Theme system with dark mode support
116
+ 5. State management setup
117
+ 6. API client configuration
118
+ 7. Common components (Button, Card, Input, Header)
119
+ 8. App configuration and assets setup`,skills:[],outputType:"page",tags:["mobile","react-native","expo","flutter"]},{name:"chrome-extension",description:"Browser extension with popup, content script, background worker, and options",prompt:`Create a browser extension (Chrome/Firefox compatible) with:
120
+ 1. manifest.json (Manifest V3)
121
+ 2. Popup page with UI
122
+ 3. Content script that modifies web pages
123
+ 4. Background service worker for event handling
124
+ 5. Options/settings page
125
+ 6. Storage management for user preferences
126
+ 7. Message passing between popup, content script, and background
127
+ 8. Icons and assets structure
128
+ 9. Build script`,skills:[],outputType:"website",tags:["extension","chrome","browser","plugin"]},{name:"data-pipeline",description:"Data processing pipeline with ingestion, transformation, and output stages",prompt:`Create a data processing pipeline with:
129
+ 1. Data ingestion from multiple sources (file, API, database)
130
+ 2. Transformation stage with configurable processors
131
+ 3. Validation and error handling at each stage
132
+ 4. Output to multiple destinations (file, database, API)
133
+ 5. Logging and monitoring
134
+ 6. Configuration file for pipeline definition
135
+ 7. CLI runner with progress reporting
136
+ 8. Test suite with sample data
137
+ 9. Docker configuration`,skills:[],outputType:"script",tags:["data","pipeline","etl","processing"]}],ze=new It().name("create").description("scaffold a new project from a template using AI").argument("[name]","project name").option("-t, --template <template>",`template to use: ${K.map(o=>o.name).join(", ")}`).option("-p, --provider <provider>","AI provider (claude-code, claude)","claude-code").option("-m, --model <model>","model to use").option("--api-key <key>","API key").option("-c, --cwd <cwd>","parent directory",process.cwd()).option("--list","list available templates",!1).option("-y, --yes","skip confirmation prompts",!1).action(async(o,e)=>{try{if(e.list){t.break(),console.log($.bold(" Available templates:")),t.break();for(let d of K)console.log(` ${$.green(d.name)}`),console.log(` ${$.dim(d.description)}`),console.log(` ${$.dim("tags:")} ${d.tags.map(p=>$.cyan(p)).join(", ")}`),t.break();return}if(!o){let d=await re({type:"text",name:"name",message:"Project name:",validate:p=>p.trim()?/^[a-z0-9-_.]+$/.test(p.trim())?!0:"Use lowercase letters, numbers, hyphens, dots, or underscores":"Name is required"});d.name||(t.warn("No name provided. Exiting."),process.exit(0)),o=d.name}let n;if(e.template)n=K.find(d=>d.name===e.template),n||(t.error(`Template "${e.template}" not found. Available: ${K.map(d=>d.name).join(", ")}`),t.info(`Run ${$.green("agentx create --list")} to see all templates.`),process.exit(1));else{let{selected:d}=await re({type:"select",name:"selected",message:"Choose a template:",choices:[...K.map(p=>({title:`${p.name} \u2014 ${p.description}`,value:p.name})),{title:"Custom \u2014 describe your own project",value:"_custom"}]});if(d||(t.warn("No template selected. Exiting."),process.exit(0)),d==="_custom"){let{description:p}=await re({type:"text",name:"description",message:"Describe the project you want to create:",validate:f=>f.trim()?!0:"Description is required"});p||(t.warn("No description provided. Exiting."),process.exit(0)),n={name:"custom",description:p,prompt:p,skills:[],outputType:"website",tags:[]}}else n=K.find(p=>p.name===d)}let r=Ve.resolve(e.cwd,o);if(Tt(r)){if(!e.yes){let{overwrite:d}=await re({type:"confirm",name:"overwrite",message:`Directory "${o}" already exists. Continue?`,initial:!1});if(!d){t.info("Cancelled.");return}}}else await St.mkdir(r,{recursive:!0});t.break(),t.info(`Project: ${$.bold(o)}`),t.info(`Template: ${$.bold(n.name)}`),t.info(`Directory: ${$.dim(r)}`),t.break();let i=At("Generating project from template...").start(),s=await je({task:`Create a new project called "${o}" in the current directory.
138
+
139
+ ${n.prompt}
140
+
141
+ Generate all files relative to the project root. Include a README.md explaining the project and how to get started.`,outputType:n.outputType,cwd:r,overwrite:!0,dryRun:!1,provider:e.provider,model:e.model,apiKey:e.apiKey,context7:!0,interactive:!1,maxSteps:5});if(i.stop(),t.break(),s.content&&(console.log(s.content),t.break()),s.files.written.length){t.success(`Created ${s.files.written.length} file(s) in ${$.bold(o)}/`);for(let d of s.files.written){let p=Ve.relative(r,d);console.log(` ${$.green("+")} ${p}`)}}if(s.files.errors.length){t.error(`${s.files.errors.length} file(s) failed:`);for(let d of s.files.errors)console.log(` ${$.red("x")} ${d}`)}t.break(),t.info("Next steps:"),console.log(` ${$.green("cd")} ${o}`),console.log(` ${$.green("agentx inspect")} \u2014 see what was generated`),console.log(` ${$.green("agentx evolve")} \u2014 modify and extend`),t.break(),s.tokensUsed&&t.info(`Tokens used: ${s.tokensUsed}`)}catch(n){u(n)}});import{existsSync as Je,promises as Pt}from"fs";import Qe from"path";import ye from"chalk";import{Command as Et}from"commander";var Xe=new Et().name("run").description("start the agentx runtime \u2014 an intelligent framework that receives requests, learns, auto-heals, and self-enhances").option("--port <port>","server port","3170").option("--host <host>","server host","0.0.0.0").option("-p, --provider <provider>","AI provider (claude-code, claude)","claude-code").option("-m, --model <model>","model to use").option("--api-key <key>","API key").option("-c, --cwd <cwd>","working directory",process.cwd()).option("--no-memory","disable memory/learning").option("--no-heal","disable auto-heal").option("--no-enhance","disable self-enhancement").option("--test-cmd <cmd>","test command for auto-heal").option("--build-cmd <cmd>","build command for auto-heal").option("--no-cors","disable CORS").action(async o=>{try{let e=Qe.resolve(o.cwd);Je(e)||(t.error(`The path ${e} does not exist.`),process.exit(1));let n=Qe.resolve(e,"agentx.config.json"),r={};if(Je(n))try{let d=await Pt.readFile(n,"utf8");r=JSON.parse(d),t.info(`Loaded config from ${ye.dim("agentx.config.json")}`)}catch{t.warn("Failed to parse agentx.config.json, using defaults")}let i={port:parseInt(o.port,10)||r.port,host:o.host||r.host,provider:o.provider||r.provider,model:o.model||r.model,apiKey:o.apiKey||r.apiKey,cwd:e,memory:{enabled:o.memory!==!1&&r.memory?.enabled!==!1},heal:{enabled:o.heal!==!1&&r.heal?.enabled!==!1,testCommand:o.testCmd||r.heal?.testCommand,buildCommand:o.buildCmd||r.heal?.buildCommand},enhance:{enabled:o.enhance!==!1&&r.enhance?.enabled!==!1,autoSkills:r.enhance?.autoSkills!==!1},cors:o.cors!==!1};console.log(""),console.log(ye.bold.cyan(" \u2591\u2591\u2591 agentx runtime \u2591\u2591\u2591")),console.log(ye.dim(" the intelligent framework")),console.log(""),await new Oe(i).start()}catch(e){u(e)}});import{existsSync as Rt}from"fs";import jt from"path";import c from"chalk";import{Command as Mt}from"commander";import Dt from"ora";var Ze=new Mt().name("inspect").aliases(["info","ctx"]).description("show what the agent knows about your project \u2014 tech stack, schemas, skills, and more").option("-c, --cwd <cwd>","working directory",process.cwd()).option("--json","output as JSON",!1).option("--verbose","show full schema and model contents",!1).action(async o=>{try{let e=jt.resolve(o.cwd);Rt(e)||(t.error(`The path ${e} does not exist.`),process.exit(1));let n=Dt("Analyzing project...").start(),r=await te(e,"inspect",{context7:{enabled:!1}});if(n.stop(),o.json){console.log(JSON.stringify({techStack:r.techStack,schemas:r.schemas,skills:r.skills.map(a=>({name:a.frontmatter.name,description:a.frontmatter.description,source:a.source,tags:a.frontmatter.tags}))},null,2));return}t.break(),console.log(c.bold.cyan(" agentx inspect")),console.log(c.dim(` ${e}`)),t.break();let{techStack:i}=r;if(i.languages.length){console.log(c.bold(" Languages"));for(let a of i.languages)console.log(` ${c.green("\u25CF")} ${a.name}${a.version?c.dim(` ${a.version}`):""}${a.configFile?c.dim(` (${a.configFile})`):""}`);t.break()}if(i.frameworks.length){console.log(c.bold(" Frameworks"));for(let a of i.frameworks){let m=a.type==="frontend"?c.blue:a.type==="backend"?c.yellow:a.type==="fullstack"?c.magenta:a.type==="mobile"?c.green:c.dim;console.log(` ${c.green("\u25CF")} ${a.name}${a.version?c.dim(` @${a.version}`):""} ${m(`[${a.type}]`)}`)}t.break()}if(i.packageManager&&(console.log(c.bold(" Package Manager")),console.log(` ${c.green("\u25CF")} ${i.packageManager}`),t.break()),i.databases.length){console.log(c.bold(" Databases"));for(let a of i.databases)console.log(` ${c.green("\u25CF")} ${a}`);t.break()}if(i.styling.length){console.log(c.bold(" Styling"));for(let a of i.styling)console.log(` ${c.green("\u25CF")} ${a}`);t.break()}if(i.testing.length){console.log(c.bold(" Testing"));for(let a of i.testing)console.log(` ${c.green("\u25CF")} ${a}`);t.break()}if(i.deployment.length){console.log(c.bold(" Deployment"));for(let a of i.deployment)console.log(` ${c.green("\u25CF")} ${a}`);t.break()}i.monorepo&&(console.log(c.bold(" Monorepo")),console.log(` ${c.green("\u25CF")} yes`),t.break());let{schemas:s}=r,d=s.database||s.api||s.env||s.models?.length;if(d){if(console.log(c.bold(" Schemas Detected")),s.database&&(console.log(` ${c.green("\u25CF")} Database: ${c.cyan(s.database.type)}${s.database.tables?.length?c.dim(` (${s.database.tables.length} tables: ${s.database.tables.slice(0,5).join(", ")}${s.database.tables.length>5?"...":""})`):""}`),o.verbose&&s.database.content)){console.log(c.dim(" \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"));for(let a of s.database.content.split(`
142
+ `).slice(0,20))console.log(c.dim(` \u2502 ${a}`));console.log(c.dim(" \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"))}s.api&&console.log(` ${c.green("\u25CF")} API: ${c.cyan(s.api.type)}`),s.env&&console.log(` ${c.green("\u25CF")} Environment: ${c.cyan(`${s.env.variables.length} variables`)}${s.env.variables.filter(a=>a.required).length?c.dim(` (${s.env.variables.filter(a=>a.required).length} required)`):""}`),s.models?.length&&console.log(` ${c.green("\u25CF")} Models: ${c.cyan(`${s.models.length} file(s)`)} ${c.dim(s.models.map(a=>a.path).join(", "))}`),t.break()}if(r.skills.length){console.log(c.bold(" Skills"));for(let a of r.skills){let m=a.source==="remote"?c.blue(`[${a.packageId||"remote"}]`):a.source==="generated"?c.magenta("[generated]"):c.dim("[local]");console.log(` ${c.green("\u25CF")} ${a.frontmatter.name} ${m}`),console.log(` ${c.dim(a.frontmatter.description)}`)}t.break()}else console.log(c.bold(" Skills")),console.log(` ${c.dim("none installed")} \u2014 run ${c.green("agentx skill install <owner/repo>")} or ${c.green("agentx skill create <name>")}`),t.break();let p=Object.keys(i.dependencies).length,f=Object.keys(i.devDependencies).length;if(p||f){if(console.log(c.bold(" Dependencies")),console.log(` ${c.green("\u25CF")} ${p} dependencies, ${f} devDependencies`),o.verbose){let a=Object.entries(i.dependencies).slice(0,15);for(let[m,w]of a)console.log(` ${c.dim(m)} ${c.dim(w)}`);p>15&&console.log(c.dim(` ... and ${p-15} more`))}t.break()}let g=[];i.languages.length&&g.push(`${i.languages.length} lang(s)`),i.frameworks.length&&g.push(`${i.frameworks.length} framework(s)`),d&&g.push("schemas detected"),r.skills.length&&g.push(`${r.skills.length} skill(s)`),console.log(c.dim(` Summary: ${g.join(" \xB7 ")}`)),t.break()}catch(e){u(e)}});import{existsSync as Nt,promises as et}from"fs";import G from"path";import k from"chalk";import{Command as Ot}from"commander";import tt from"ora";import ke from"prompts";var B=new Ot().name("skill").description("manage agent skills \u2014 install, create, list, and generate");B.command("install").aliases(["add","i"]).description("install a skill package from skills.sh or GitHub").argument("<package>","skill package (e.g., intellectronica/agent-skills)").option("-c, --cwd <cwd>","working directory",process.cwd()).action(async(o,e)=>{try{let n=G.resolve(e.cwd),r=tt(`Installing skill: ${o}`).start(),i=await Me(o,n);if(r.stop(),i.length){t.success(`Installed ${i.length} skill(s):`);for(let s of i)console.log(` ${k.green("+")} ${s.frontmatter.name} \u2014 ${s.frontmatter.description}`)}else t.warn("No skills found in the package.")}catch(n){u(n)}});B.command("list").aliases(["ls"]).description("list installed skills").option("-c, --cwd <cwd>","working directory",process.cwd()).action(async o=>{try{let e=G.resolve(o.cwd),n=await pe(e);if(!n.length){t.info("No skills installed. Install one with:"),console.log(` ${k.green("agentx skill install")} ${k.dim("<owner/repo>")}`);return}t.info(`Found ${n.length} skill(s):`),t.break();for(let r of n){let i=r.source==="remote"?k.blue(`[${r.packageId}]`):r.source==="generated"?k.magenta("[generated]"):k.dim("[local]");console.log(` ${k.bold(r.frontmatter.name)} ${i}`),console.log(` ${k.dim(r.frontmatter.description)}`),r.frontmatter.tags?.length&&console.log(` ${k.dim("tags:")} ${r.frontmatter.tags.map(s=>k.cyan(s)).join(", ")}`),r.path&&console.log(` ${k.dim("path:")} ${r.path}`),t.break()}}catch(e){u(e)}});B.command("create").description("create a new skill interactively or from a description").argument("[name]","skill name").option("-d, --description <desc>","skill description").option("--tags <tags>","comma-separated tags").option("-p, --provider <provider>","AI provider for generation (claude-code, claude)","claude-code").option("-m, --model <model>","model to use").option("--api-key <key>","API key").option("-c, --cwd <cwd>","working directory",process.cwd()).option("--no-ai","create a blank skill template without AI").action(async(o,e)=>{try{let n=G.resolve(e.cwd);if(!o){let f=await ke({type:"text",name:"name",message:"Skill name:",validate:g=>g.trim()?/^[a-z0-9-]+$/.test(g.trim())?!0:"Use lowercase letters, numbers, and hyphens only":"Name is required"});f.name||(t.warn("No name provided. Exiting."),process.exit(0)),o=f.name}let r=e.description;if(!r){let f=await ke({type:"text",name:"description",message:"Skill description:",validate:g=>g.trim()?!0:"Description is required"});f.description||(t.warn("No description provided. Exiting."),process.exit(0)),r=f.description}let i=e.tags?e.tags.split(",").map(f=>f.trim()):void 0,s=G.resolve(n,".skills",o),d=G.resolve(s,"SKILL.md");if(Nt(d)){let{overwrite:f}=await ke({type:"confirm",name:"overwrite",message:`Skill "${o}" already exists. Overwrite?`,initial:!1});if(!f){t.info("Skipped.");return}}let p;if(e.ai===!1)p=await De(o,r,`# ${o}
143
+
144
+ ## Instructions
145
+
146
+ Add your skill instructions here.
147
+
148
+ ## Examples
149
+
150
+ Add examples here.`,i);else{await Z(e.apiKey)||(t.error("No credentials configured. Run `agentx model` to set up."),process.exit(1));let g=tt("Detecting tech stack...").start(),a=await Se(n);g.text="Generating skill with AI...";let m=U(e.provider,e.apiKey),w=await Ne(m,o,r,a,{tags:i});g.stop(),p=w.content}await et.mkdir(s,{recursive:!0}),await et.writeFile(d,p,"utf8"),t.success(`Created skill: ${d}`),t.break(),t.info("The skill will be automatically loaded for future generations."),t.info(`To share it, push to GitHub and others can install with: ${k.green("agentx skill install <your-username>/<your-repo>")}`)}catch(n){u(n)}});B.command("inspect").description("show details of an installed skill").argument("<name>","skill name").option("-c, --cwd <cwd>","working directory",process.cwd()).action(async(o,e)=>{try{let n=G.resolve(e.cwd),i=(await pe(n)).find(s=>s.frontmatter.name===o||s.path?.includes(o));if(!i){t.error(`Skill "${o}" not found.`),t.info(`Run ${k.green("agentx skill list")} to see installed skills.`);return}console.log(k.bold(`
151
+ ${i.frontmatter.name}`)),console.log(` ${i.frontmatter.description}`),t.break(),i.frontmatter.tags?.length&&console.log(` ${k.dim("Tags:")} ${i.frontmatter.tags.join(", ")}`),i.packageId&&console.log(` ${k.dim("Package:")} ${i.packageId}`),i.path&&console.log(` ${k.dim("Path:")} ${i.path}`),t.break(),console.log(k.dim(" --- Instructions ---")),t.break(),console.log(i.instructions.split(`
152
+ `).map(s=>` ${s}`).join(`
153
+ `)),t.break()}catch(n){u(n)}});import be from"chalk";import{Command as Ft}from"commander";var ot=new Ft().name("serve").description("run agentx as an MCP server for AI editors (Claude Code, Cursor, Windsurf, etc.)").option("--stdio","use stdio transport (default)",!0).option("-c, --cwd <cwd>","working directory",process.cwd()).action(async o=>{try{o.stdio!==!1?await Fe():(t.error("Only stdio transport is currently supported."),t.info(`Usage: ${be.green("agentx serve --stdio")} or configure in your MCP client.`),t.break(),t.info("Add to Claude Code:"),t.info(be.dim(" claude mcp add agentx -- npx agentx serve --stdio")),t.break(),t.info("Add to Cursor/MCP config:"),t.info(be.dim(JSON.stringify({mcpServers:{agentx:{command:"npx",args:["agentx","serve","--stdio"]}}},null,2))))}catch(e){u(e)}});import F from"chalk";import{Command as Lt}from"commander";var Ut=[{id:"claude-sonnet-4-20250514",label:"anthropic/claude-sonnet-4",hint:"Claude Sonnet 4 \xB7 ctx 200k \xB7 recommended"},{id:"claude-opus-4-20250514",label:"anthropic/claude-opus-4-5",hint:"Claude Opus 4.5 \xB7 ctx 200k \xB7 reasoning"},{id:"claude-haiku-4-20250514",label:"anthropic/claude-haiku-4",hint:"Claude Haiku 4 \xB7 ctx 200k \xB7 fast"}],se=new Lt().name("model").description("configure AI provider, credentials, and model");se.command("setup",{isDefault:!0}).description("interactively configure provider and model").action(async()=>{try{await Te()||process.exit(0)}catch(o){u(o)}});se.command("show").description("display current provider and model configuration").action(async()=>{try{let o=X();o||(t.warn("No configuration found. Run `agentx model` to set up."),process.exit(0));let e=Ut.find(n=>n.id===o.model)?.label||o.model;console.log(F.bold(`
154
+ Current configuration:`)),console.log(` Provider: ${F.cyan("anthropic")} (${o.authType})`),console.log(` Model: ${F.cyan(e)}`),console.log(` Token: ${F.dim(_t(o.token))}`),console.log(` File: ${F.dim("~/.agentx/auth.json")}`),process.env.ANTHROPIC_API_KEY&&console.log(F.yellow(`
155
+ Note: ANTHROPIC_API_KEY env var is set (takes priority)`)),process.env.ANTHROPIC_OAUTH_TOKEN&&console.log(F.yellow(`
156
+ Note: ANTHROPIC_OAUTH_TOKEN env var is set (takes priority)`)),console.log()}catch(o){u(o)}});function _t(o){return o.length<12?"***":o.slice(0,10)+"..."+o.slice(-4)}import{Command as Ht}from"commander";import A from"chalk";import Kt from"ora";var Y=new Ht().name("git").description("AI-powered git operations");Y.command("status").alias("s").description("show git status with summary").option("-c, --cwd <cwd>","working directory",process.cwd()).action(async o=>{try{let e=new z(o.cwd);await e.isRepo()||(t.error("Not a git repository"),process.exit(1));let n=await e.status();if(t.break(),t.info(`Branch: ${A.bold(n.branch)}`),t.break(),n.isClean){t.success("Working tree clean");return}if(n.staged.length){t.success(`Staged (${n.staged.length}):`);for(let r of n.staged)console.log(` ${A.green("+")} ${r}`)}if(n.modified.length){t.warn(`Modified (${n.modified.length}):`);for(let r of n.modified)console.log(` ${A.yellow("~")} ${r}`)}if(n.untracked.length){console.log(A.dim(`Untracked (${n.untracked.length}):`));for(let r of n.untracked)console.log(` ${A.dim("?")} ${r}`)}if(n.deleted.length){t.error(`Deleted (${n.deleted.length}):`);for(let r of n.deleted)console.log(` ${A.red("-")} ${r}`)}t.break()}catch(e){u(e)}});Y.command("commit").alias("c").description("create an AI-generated commit message and commit").option("-m, --message <message>","use a custom commit message").option("-a, --all","stage all changes before committing",!1).option("--ai","generate commit message with AI",!0).option("-c, --cwd <cwd>","working directory",process.cwd()).action(async o=>{try{let e=new z(o.cwd);await e.isRepo()||(t.error("Not a git repository"),process.exit(1)),o.all&&await e.addAll(),(await e.status()).staged.length===0&&(t.warn("Nothing staged to commit. Use --all to stage everything."),process.exit(0));let r=o.message;if(!r)if(o.ai){let s=Kt("Generating commit message...").start();try{let d=U();r=await e.generateCommitMessage(d),s.stop(),t.info(`Message: ${A.bold(r)}`)}catch{s.stop(),r=await e.generateCommitMessage(),t.info(`Message: ${A.bold(r)}`)}}else r=await e.generateCommitMessage();let i=await e.commit(r);t.break(),t.success(`[${i.hash}] ${i.message} (${i.filesChanged} file(s))`)}catch(e){u(e)}});Y.command("diff").alias("d").description("show diff of changes").option("-s, --staged","show staged changes",!1).option("-c, --cwd <cwd>","working directory",process.cwd()).action(async o=>{try{let n=await new z(o.cwd).diff(o.staged);if(!n.trim()){t.info(o.staged?"No staged changes":"No changes");return}console.log(n)}catch(e){u(e)}});Y.command("log").alias("l").description("show recent commits").option("-n, --count <n>","number of commits to show","10").option("-c, --cwd <cwd>","working directory",process.cwd()).action(async o=>{try{let n=await new z(o.cwd).log(parseInt(o.count));if(!n.length){t.info("No commits yet");return}t.break();for(let r of n)console.log(`${A.yellow(r.shortHash)} ${r.message} ${A.dim(`\u2014 ${r.author}`)}`);t.break()}catch(e){u(e)}});import{Command as Gt}from"commander";var it=new Gt().name("a2a").description("start an A2A (Agent-to-Agent) protocol server for external agent integration").option("--port <port>","server port","3171").option("--host <host>","server host","0.0.0.0").option("-p, --provider <provider>","AI provider","claude-code").option("-m, --model <model>","model to use").option("--api-key <key>","API key for the provider").option("-c, --cwd <cwd>","working directory",process.cwd()).option("--no-cors","disable CORS headers").action(async o=>{await new _e({port:parseInt(o.port,10),host:o.host,provider:o.provider,model:o.model,apiKey:o.apiKey,cwd:o.cwd,cors:o.cors!==!1}).start()});import{Command as Bt}from"commander";var nt=new Bt().name("daemon").description("start the agentx daemon \u2014 channels, crons, agents, and mesh").option("-c, --config <path>","path to agentx.json config file").action(async o=>{await new He(o.config).start()});import{Command as Yt}from"commander";process.on("SIGINT",()=>process.exit(0));process.on("SIGTERM",()=>process.exit(0));async function Wt(){let o=await oe(),e=process.cwd();Ee(e,x);let n=new Yt().name("agentx").description("the AI coding agent \u2014 generate, evolve, chat, and manage your codebase with AI").version(o.version||"1.0.0","-v, --version","display the version number");n.addCommand(Ge).addCommand(We).addCommand(qe).addCommand(Y).addCommand(ze).addCommand(Xe).addCommand(Ze).addCommand(B).addCommand(ot).addCommand(se).addCommand(it).addCommand(nt),process.argv.slice(2).length===0&&process.stdin.isTTY&&process.argv.push("chat"),n.parse()}Wt();
157
+ //# sourceMappingURL=cli.js.map