UNPKG

@microfox/cli

Version:

Universal CLI tool for creating modern TypeScript packages with npm availability checking

676 lines (664 loc) 30.7 kB
#!/usr/bin/env node "use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); // src/cli.ts var import_commander = require("commander"); var import_chalk5 = __toESM(require("chalk")); // src/commands/kickstart.ts var import_fs = __toESM(require("fs")); var import_path = __toESM(require("path")); var import_chalk = __toESM(require("chalk")); var import_readline_sync = __toESM(require("readline-sync")); var import_inquirer = __toESM(require("inquirer")); // src/utils/getProjectRoot.ts var getWorkingDirectory = () => { return process.cwd(); }; // src/utils/npmChecker.ts async function isPackageNameAvailable(packageName) { try { const controller = new AbortController(); const timeoutId = setTimeout(() => controller.abort(), 5e3); const response = await fetch(`https://registry.npmjs.org/${packageName}`, { signal: controller.signal }); clearTimeout(timeoutId); if (response.ok) { return false; } if (response.status === 404) { return true; } console.warn( `Warning: Unexpected status ${response.status} when checking npm availability for ${packageName}. Proceeding with caution.` ); return false; } catch (error) { if (error.name === "AbortError") { console.warn( `Warning: Timeout when checking npm availability for ${packageName}. Proceeding with caution.` ); } else { console.warn( `Warning: Could not check npm availability for ${packageName}. Proceeding with caution.` ); } return false; } } async function checkPackageNameAndPrompt(packageName) { const readlineSync2 = require("readline-sync"); let currentName = (packageName == null ? void 0 : packageName.startsWith("@microfox/")) ? packageName : `@microfox/${packageName}`; while (true) { console.log(`\u{1F50D} Checking npm availability for "${currentName}"...`); const isAvailable = await isPackageNameAvailable(currentName); if (isAvailable) { console.log(`\u2705 Package name "${currentName}" is available on npm!`); return currentName; } else { console.log(`\u274C Package name "${currentName}" is already taken on npm.`); const newName = readlineSync2.question( "Please enter a new package name: " ); if (!newName || newName.trim() === "") { console.log("\u274C Invalid package name. Please try again."); continue; } currentName = newName.trim(); } } } // src/commands/kickstart.ts async function createAgentProject(agentName) { const workingDir = getWorkingDirectory(); const agentDir = import_path.default.join(workingDir, agentName); if (import_fs.default.existsSync(agentDir)) { throw new Error(`Directory already exists at ${agentDir}`); } console.log( import_chalk.default.blue( `\u{1F680} Creating agent ${import_chalk.default.bold(agentName)} at ${agentDir} ` ) ); import_fs.default.mkdirSync(agentDir, { recursive: true }); const templatePath = import_path.default.resolve(__dirname, "agent-template.txt"); const templateContent = import_fs.default.readFileSync(templatePath, "utf-8"); const fileSections = templateContent.split("--- filename: ").slice(1); for (const section of fileSections) { const lines = section.split("\n"); const filePath = lines.shift().trim(); const content = lines.join("\n").replace(/<%= agentName %>/g, agentName); const destPath = import_path.default.join(agentDir, filePath); const destDir = import_path.default.dirname(destPath); if (!import_fs.default.existsSync(destDir)) { import_fs.default.mkdirSync(destDir, { recursive: true }); } import_fs.default.writeFileSync(destPath, content); console.log(import_chalk.default.green(`\u2705 Created ${filePath}`)); } } async function createPackageProject(packageName) { const simpleName = packageName.includes("/") ? packageName.split("/")[1] : packageName; const titleName = simpleName.split("-").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" "); const description = `A TypeScript SDK for ${titleName}.`; const className = simpleName.split("-").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join("") + "Sdk"; const workingDir = getWorkingDirectory(); const packageDir = import_path.default.join(workingDir, simpleName); if (import_fs.default.existsSync(packageDir)) { throw new Error(`Directory already exists at ${packageDir}`); } console.log( import_chalk.default.blue( `\u{1F680} Creating package ${import_chalk.default.bold(packageName)} at ${packageDir} ` ) ); import_fs.default.mkdirSync(packageDir, { recursive: true }); const templatePath = import_path.default.resolve(__dirname, "package-template.txt"); const templateContent = import_fs.default.readFileSync(templatePath, "utf-8"); const fileSections = templateContent.split("--- filename: ").slice(1); for (const section of fileSections) { const lines = section.split("\n"); const filePath = lines.shift().trim().replace(/<%= simpleName %>/g, simpleName); let content = lines.join("\n"); content = content.replace(/<%= packageName %>/g, packageName); content = content.replace(/<%= simpleName %>/g, simpleName); content = content.replace(/<%= titleName %>/g, titleName); content = content.replace(/<%= description %>/g, description); content = content.replace(/<%= className %>/g, className); const destPath = import_path.default.join(packageDir, filePath); const destDir = import_path.default.dirname(destPath); if (!import_fs.default.existsSync(destDir)) { import_fs.default.mkdirSync(destDir, { recursive: true }); } import_fs.default.writeFileSync(destPath, content); console.log(import_chalk.default.green(`\u2705 Created ${filePath}`)); } const docsDir = import_path.default.join(packageDir, "docs"); const docsConstructors = import_path.default.join(docsDir, "constructors"); const docsFunctions = import_path.default.join(docsDir, "functions"); import_fs.default.mkdirSync(docsDir, { recursive: true }); import_fs.default.mkdirSync(docsConstructors, { recursive: true }); import_fs.default.mkdirSync(docsFunctions, { recursive: true }); } async function createBackgroundAgentProject(agentName) { const workingDir = getWorkingDirectory(); const agentDir = import_path.default.join(workingDir, agentName); if (import_fs.default.existsSync(agentDir)) { throw new Error(`Directory already exists at ${agentDir}`); } console.log( import_chalk.default.blue( `\u{1F680} Creating background agent ${import_chalk.default.bold(agentName)} at ${agentDir} ` ) ); import_fs.default.mkdirSync(agentDir, { recursive: true }); const templateDir = import_path.default.resolve(__dirname, "background-agent"); const copyTemplates = (src, dest) => { const entries = import_fs.default.readdirSync(src, { withFileTypes: true }); for (const entry of entries) { const srcPath = import_path.default.join(src, entry.name); const destPath = import_path.default.join(dest, entry.name.replace(/\.txt$/, "")); if (entry.isDirectory()) { import_fs.default.mkdirSync(destPath, { recursive: true }); copyTemplates(srcPath, destPath); } else if (entry.name.endsWith(".txt")) { const templateContent = import_fs.default.readFileSync(srcPath, "utf-8"); const content = templateContent.replace(/<%= agentName %>/g, agentName); import_fs.default.writeFileSync(destPath, content); console.log(import_chalk.default.green(`\u2705 Created ${import_path.default.relative(agentDir, destPath)}`)); } } }; copyTemplates(templateDir, agentDir); } async function kickstartCommand() { console.log(import_chalk.default.cyan("\u{1F680} Let's kickstart your new project!\n")); const { boilerplateType } = await import_inquirer.default.prompt([ { type: "list", name: "boilerplateType", message: "Select boilerplate type:", choices: ["package", "agent"] } ]); if (!boilerplateType) { console.log(import_chalk.default.yellow("Operation cancelled.")); return; } if (boilerplateType === "agent") { const { agentType } = await import_inquirer.default.prompt([ { type: "list", name: "agentType", message: "Select agent type:", choices: ["plain", "background"] } ]); if (agentType === "plain") { const agentName = import_readline_sync.default.question( import_chalk.default.yellow("\u{1F4E6} Enter agent name: ") ); if (!agentName.trim()) { throw new Error("Agent name cannot be empty"); } await createAgentProject(agentName.trim()); console.log( import_chalk.default.green( ` \u{1F389} Successfully created agent ${import_chalk.default.bold(agentName)}!` ) ); console.log(import_chalk.default.gray(`\u{1F4CD} Located at ${import_path.default.join(getWorkingDirectory(), agentName)}`)); console.log(import_chalk.default.yellow("\n\u{1F4A1} Next steps:")); console.log(import_chalk.default.yellow(` 1. cd ${agentName}`)); console.log(import_chalk.default.yellow(" 2. npm install")); console.log(import_chalk.default.yellow(" 3. Configure your env.json")); console.log(import_chalk.default.yellow(" 4. npm run dev")); console.log(import_chalk.default.yellow(" 5. Start developing your agent!")); } else if (agentType === "background") { const agentName = import_readline_sync.default.question( import_chalk.default.yellow("\u{1F4E6} Enter agent name: ") ); if (!agentName.trim()) { throw new Error("Agent name cannot be empty"); } await createBackgroundAgentProject(agentName.trim()); console.log( import_chalk.default.green( ` \u{1F389} Successfully created background agent ${import_chalk.default.bold(agentName)}!` ) ); console.log(import_chalk.default.gray(`\u{1F4CD} Located at ${import_path.default.join(getWorkingDirectory(), agentName)}`)); console.log(import_chalk.default.yellow("\n\u{1F4A1} Next steps:")); console.log(import_chalk.default.yellow(` 1. cd ${agentName}`)); console.log(import_chalk.default.yellow(" 2. npm install")); console.log(import_chalk.default.yellow(" 3. Configure your env.json")); console.log(import_chalk.default.yellow(" 4. npm run dev")); console.log(import_chalk.default.yellow(" 5. Start developing your agent!")); } } else if (boilerplateType === "package") { const packageName = import_readline_sync.default.question( import_chalk.default.yellow("\u{1F4E6} Enter package name: ") ); if (!packageName.trim()) { throw new Error("Package name cannot be empty"); } const finalPackageName = await checkPackageNameAndPrompt(`@microfox/${packageName.trim()}`); await createPackageProject(finalPackageName); const simpleName = finalPackageName.includes("/") ? finalPackageName.split("/")[1] : finalPackageName; console.log( import_chalk.default.green( ` \u{1F389} Successfully created package ${import_chalk.default.bold(finalPackageName)}!` ) ); console.log(import_chalk.default.gray(`\u{1F4CD} Located at ${import_path.default.join(getWorkingDirectory(), simpleName)}`)); console.log(import_chalk.default.yellow("\n\u{1F4A1} Next steps:")); console.log(import_chalk.default.yellow(` 1. cd ${simpleName}`)); console.log(import_chalk.default.yellow(" 2. npm install")); console.log(import_chalk.default.yellow(" 3. npm run build")); console.log(import_chalk.default.yellow(" 4. npm test")); console.log(import_chalk.default.yellow(" 5. Start developing your SDK!")); console.log( import_chalk.default.gray( ` \u{1F4DA} Your package is ready to be published to npm as "${finalPackageName}"` ) ); } else { console.log(import_chalk.default.red('Invalid boilerplate type selected. Please choose "package" or "agent".')); } } // src/commands/push.ts var import_fs2 = __toESM(require("fs")); var import_path2 = __toESM(require("path")); var import_chalk2 = __toESM(require("chalk")); var import_axios = __toESM(require("axios")); var import_micromatch = __toESM(require("micromatch")); var API_ENDPOINT = "https://staging-cicd.microfox.app/api/deployments/new-agent-cli"; var getDirectoryFiles = (dir, basePath = "", ignorePatterns) => { const structure = []; const items = import_fs2.default.readdirSync(dir, { withFileTypes: true }); for (const item of items) { const relativePath = import_path2.default.join(basePath, item.name); if (import_micromatch.default.isMatch(relativePath, ignorePatterns)) { continue; } if (item.isDirectory()) { structure.push(...getDirectoryFiles(import_path2.default.join(dir, item.name), relativePath, ignorePatterns)); } else { structure.push({ type: "file", name: item.name, path: relativePath.replace(/\\/g, "/"), content: import_fs2.default.readFileSync(import_path2.default.join(dir, item.name), "utf-8") }); } } return structure; }; async function pushCommand() { const cwd = process.cwd(); const microfoxConfigPath = import_path2.default.join(cwd, "microfox.json"); if (!import_fs2.default.existsSync(microfoxConfigPath)) { console.error(import_chalk2.default.red("\u274C Error: `microfox.json` not found in the current directory.")); console.log(import_chalk2.default.yellow("This command must be run from the root of an agent project.")); process.exit(1); } console.log(import_chalk2.default.cyan("\u{1F680} Pushing your agent to Microfox...")); const microfoxConfig = JSON.parse(import_fs2.default.readFileSync(microfoxConfigPath, "utf-8")); let agentApiKey; const envPath = import_path2.default.join(cwd, "env.json"); if (import_fs2.default.existsSync(envPath)) { try { const envConfig = JSON.parse(import_fs2.default.readFileSync(envPath, "utf-8")); agentApiKey = envConfig.AGENT_API_KEY; } catch (e) { console.warn(import_chalk2.default.yellow("\u26A0\uFE0F Could not read or parse `env.json`. The AGENT_API_KEY will not be sent.")); } } const stage = microfoxConfig.stage || "prod"; const ignored = microfoxConfig.ignored || []; const defaultIgnore = ["node_modules/**", ".git/**", "dist/**", ".build/**", ".serverless/**", ".DS_Store", "package-lock.json", "pnpm-lock.yaml"]; const allIgnored = [...defaultIgnore, ...ignored]; const files = getDirectoryFiles(cwd, "", allIgnored); try { console.log(import_chalk2.default.blue("\u{1F4E6} Bundling and deploying your agent...")); const response = await import_axios.default.post( API_ENDPOINT, { stage, isLocal: false, dir: files }, { headers: { "x-agent-api-key": agentApiKey } } ); if (response.status === 200) { console.log(import_chalk2.default.green("\u2705 Deployment successful!")); console.log(import_chalk2.default.green(` Run ID: ${response.data.runId}`)); console.log(import_chalk2.default.green(` Message: ${response.data.message}`)); } else { console.error(import_chalk2.default.red(`\u274C Deployment failed with status: ${response.status}`)); console.error(response.data); process.exit(1); } } catch (error) { console.error(import_chalk2.default.red("\u274C An error occurred during deployment:")); if (import_axios.default.isAxiosError(error) && error.response) { console.error(import_chalk2.default.red(` Status: ${error.response.status}`)); console.error(import_chalk2.default.red(` Data: ${JSON.stringify(error.response.data, null, 2)}`)); } else { console.error(error); } process.exit(1); } } // src/commands/status.ts var import_chalk3 = __toESM(require("chalk")); var import_axios2 = __toESM(require("axios")); var import_inquirer2 = __toESM(require("inquirer")); var API_BASE_URL = "https://staging-cicd.microfox.app/api/deployment-status/agent/status/"; async function getRunId(runId) { if (runId) { return runId; } const { promptedRunId } = await import_inquirer2.default.prompt([ { type: "input", name: "promptedRunId", message: "Please enter the deployment Run ID:", validate: (input) => !!input || "Run ID cannot be empty." } ]); return promptedRunId; } async function getDeploymentData(runId) { var _a; try { const response = await import_axios2.default.get(`${API_BASE_URL}${runId}`); return response.data; } catch (error) { if (import_axios2.default.isAxiosError(error) && ((_a = error.response) == null ? void 0 : _a.status) === 404) { console.error(import_chalk3.default.red(`\u274C Error: Deployment with Run ID "${runId}" not found.`)); } else { console.error(import_chalk3.default.red("\u274C An error occurred while fetching deployment status:")); console.error(error); } process.exit(1); } } async function statusCommand(runId) { const finalRunId = await getRunId(runId); const data = await getDeploymentData(finalRunId); const deployment = data.data.deployment; console.log(import_chalk3.default.cyan.bold("\u{1F680} Deployment Status")); console.log(import_chalk3.default.gray("----------------------------------------")); console.log(`${import_chalk3.default.bold("Run ID:")} ${deployment.sha}`); console.log(`${import_chalk3.default.bold("Status:")} ${import_chalk3.default.green(deployment.status)}`); console.log(`${import_chalk3.default.bold("Description:")} ${deployment.statusDescription}`); console.log(`${import_chalk3.default.bold("Stage:")} ${deployment.stage}`); console.log(`${import_chalk3.default.bold("Start Time:")} ${deployment.startTime ? new Date(deployment.startTime).toLocaleString() : "N/A"}`); console.log(`${import_chalk3.default.bold("End Time:")} ${deployment.endTime ? new Date(deployment.endTime).toLocaleString() : "N/A"}`); console.log(`${import_chalk3.default.bold("Base URL:")} ${deployment.baseUrl ? import_chalk3.default.underline.blue(deployment.baseUrl) : "N/A"}`); console.log(import_chalk3.default.gray("----------------------------------------")); } async function logsCommand(runId) { const finalRunId = await getRunId(runId); const data = await getDeploymentData(finalRunId); const logs = data.data.deploymentLogs; console.log(import_chalk3.default.cyan.bold("\u{1F4DC} Deployment Logs")); console.log(import_chalk3.default.gray("----------------------------------------")); console.log(logs); console.log(import_chalk3.default.gray("----------------------------------------")); } async function metricsCommand(runId) { var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D; const finalRunId = await getRunId(runId); const data = await getDeploymentData(finalRunId); const metrics = data.data.deployment.metrics; console.log(import_chalk3.default.cyan.bold("\u{1F4CA} Deployment Metrics")); console.log(import_chalk3.default.gray("----------------------------------------")); console.log(import_chalk3.default.bold.underline("System")); console.log(` Platform: ${metrics.system.platform}`); console.log(` Architecture: ${metrics.system.arch}`); console.log(` Node Version: ${metrics.system.nodeVersion}`); console.log(import_chalk3.default.bold.underline("\nTiming (ms)")); for (const [step, duration] of Object.entries(((_a = metrics == null ? void 0 : metrics.timing) == null ? void 0 : _a.stepDurations) || {})) { console.log(` ${step}:`.padEnd(15) + `${duration ? `${duration}ms` : "N/A"}`); } console.log(` Total Duration:`.padEnd(15) + `${((_b = metrics == null ? void 0 : metrics.timing) == null ? void 0 : _b.totalDuration) ? `${metrics.timing.totalDuration}ms` : "N/A"}`); console.log(import_chalk3.default.bold.underline("\nResources")); console.log(import_chalk3.default.bold(" CPU:")); console.log(` Peak: ${((_d = (_c = metrics == null ? void 0 : metrics.resources) == null ? void 0 : _c.cpu) == null ? void 0 : _d.peak) ? `${(_f = (_e = metrics == null ? void 0 : metrics.resources) == null ? void 0 : _e.cpu) == null ? void 0 : _f.peak}${(_h = (_g = metrics == null ? void 0 : metrics.resources) == null ? void 0 : _g.cpu) == null ? void 0 : _h.usageUnits}` : "N/A"}`); console.log(` Average: ${((_j = (_i = metrics == null ? void 0 : metrics.resources) == null ? void 0 : _i.cpu) == null ? void 0 : _j.average) ? `${(_l = (_k = metrics == null ? void 0 : metrics.resources) == null ? void 0 : _k.cpu) == null ? void 0 : _l.average}${(_n = (_m = metrics == null ? void 0 : metrics.resources) == null ? void 0 : _m.cpu) == null ? void 0 : _n.usageUnits}` : "N/A"}`); console.log(import_chalk3.default.bold(" Memory:")); console.log(` Peak: ${((_p = (_o = metrics == null ? void 0 : metrics.resources) == null ? void 0 : _o.memory) == null ? void 0 : _p.peak) ? `${(_r = (_q = metrics == null ? void 0 : metrics.resources) == null ? void 0 : _q.memory) == null ? void 0 : _r.peak.toFixed(2)}${(_t = (_s = metrics == null ? void 0 : metrics.resources) == null ? void 0 : _s.memory) == null ? void 0 : _t.usageUnits}` : "N/A"}`); console.log(` Average: ${((_v = (_u = metrics == null ? void 0 : metrics.resources) == null ? void 0 : _u.memory) == null ? void 0 : _v.average) ? `${(_x = (_w = metrics == null ? void 0 : metrics.resources) == null ? void 0 : _w.memory) == null ? void 0 : _x.average.toFixed(2)}${(_z = (_y = metrics == null ? void 0 : metrics.resources) == null ? void 0 : _y.memory) == null ? void 0 : _z.usageUnits}` : "N/A"}`); console.log(import_chalk3.default.bold(" Disk:")); console.log(` Final Size: ${((_B = (_A = metrics == null ? void 0 : metrics.resources) == null ? void 0 : _A.diskSize) == null ? void 0 : _B.final) ? `${(((_D = (_C = metrics == null ? void 0 : metrics.resources) == null ? void 0 : _C.diskSize) == null ? void 0 : _D.final) / (1024 * 1024)).toFixed(2)} MB` : "N/A"}`); console.log(import_chalk3.default.gray("----------------------------------------")); } // src/commands/code.ts var import_chalk4 = __toESM(require("chalk")); var import_axios3 = __toESM(require("axios")); var import_child_process = require("child_process"); // src/utils/findProjectRoot.ts var import_path3 = __toESM(require("path")); var import_fs3 = __toESM(require("fs")); async function findProjectRoot(startPath = process.cwd()) { let currentPath = startPath; let count = 0; while (true) { const microfoxRootPath = import_path3.default.join(currentPath, "microfox-root"); if (import_fs3.default.existsSync(microfoxRootPath)) { return currentPath; } const parentPath = import_path3.default.dirname(currentPath); if (parentPath === currentPath || count > 10) { return null; } currentPath = parentPath; } } // src/commands/code.ts var import_path4 = __toESM(require("path")); var import_readline = __toESM(require("readline")); var NEXTJS_PORT = 3e3; var API_URL = `http://localhost:${NEXTJS_PORT}/api/agent`; var createLogger = (rl) => { return (source, message, color) => { import_readline.default.cursorTo(process.stdout, 0); import_readline.default.clearLine(process.stdout, 0); const prefix = color(`[${source}]`); const lines = message.trim().split("\n"); for (const line of lines) { console.log(`${prefix} ${line}`); } rl.prompt(true); }; }; async function codeCommand() { var _a, _b; let childProcess = null; const killProcess = () => { if (childProcess && childProcess.pid) { console.log(import_chalk4.default.yellow("\nGracefully shutting down...")); if (process.platform === "win32") { (0, import_child_process.spawn)("taskkill", ["/pid", childProcess.pid.toString(), "/f", "/t"]); } else { childProcess.kill("SIGINT"); } childProcess = null; } }; process.on("SIGINT", () => { killProcess(); process.exit(0); }); process.on("exit", killProcess); try { const projectRoot = await findProjectRoot(); if (!projectRoot) { console.error( import_chalk4.default.red("Error: Could not find project root. Make sure you are inside a Microfox project.") ); process.exit(1); } const codeAppPath = import_path4.default.join(projectRoot, "apps", "code"); console.log(import_chalk4.default.cyan(`Starting Next.js server in ${codeAppPath}...`)); childProcess = (0, import_child_process.spawn)("npm", ["run", "dev"], { cwd: codeAppPath, shell: true, env: { ...process.env, FORCE_COLOR: "true" } }); const rl = import_readline.default.createInterface({ input: process.stdin, output: process.stdout, prompt: import_chalk4.default.cyan("> ") }); const log = createLogger(rl); let serverReady = false; const onServerData = (data) => { const output = data.toString(); if (!serverReady) { process.stdout.write(output); if (output.toLowerCase().includes("ready in") || output.toLowerCase().includes("compiled successfully")) { serverReady = true; console.log(import_chalk4.default.green("\nServer is ready. You can now type your queries.")); rl.prompt(); } } else { log("nextjs", output, import_chalk4.default.gray); } }; (_a = childProcess.stdout) == null ? void 0 : _a.on("data", onServerData); (_b = childProcess.stderr) == null ? void 0 : _b.on("data", onServerData); childProcess.on("exit", (code) => { log("system", `Next.js process exited with code ${code}`, import_chalk4.default.red); process.exit(code != null ? code : 1); }); rl.on("line", async (line) => { const query = line.trim(); if (!serverReady) { log("system", "Server is not ready yet, please wait.", import_chalk4.default.yellow); rl.prompt(); return; } if (query.toLowerCase() === "exit") { rl.close(); } if (query) { try { const response = await import_axios3.default.post(API_URL, { prompt: query }); const responseData = typeof response.data === "object" ? JSON.stringify(response.data, null, 2) : response.data; log("agent", responseData, import_chalk4.default.green); } catch (error) { if (import_axios3.default.isAxiosError(error)) { log("agent", `Error: ${error.message}`, import_chalk4.default.red); } else if (error instanceof Error) { log("agent", `An unknown error occurred: ${error.message}`, import_chalk4.default.red); } } } rl.prompt(); }); rl.on("close", () => { killProcess(); process.exit(0); }); } catch (error) { killProcess(); if (error instanceof Error) { console.error(import_chalk4.default.red(`Error: ${error.message}`)); } process.exit(1); } } // package.json var version = "1.0.10"; // src/cli.ts var program = new import_commander.Command(); program.name("microfox").description("Universal CLI tool for creating and managing Microfox projects").version(version); program.command("kickstart").description("Kickstart a new TypeScript SDK or agent package").action(async () => { try { console.log(import_chalk5.default.blue("\u{1F680} Package Kickstarter\n")); await kickstartCommand(); } catch (error) { console.error(import_chalk5.default.red("\u274C Error:"), error instanceof Error ? error.message : String(error)); process.exit(1); } }); program.command("push").description("Deploy your agent to the Microfox platform").action(async () => { try { await pushCommand(); } catch (error) { console.error(import_chalk5.default.red("\u274C Error:"), error instanceof Error ? error.message : String(error)); process.exit(1); } }); program.command("status [runId]").description("Check the deployment status of your agent").action(async (runId) => { try { await statusCommand(runId); } catch (error) { console.error(import_chalk5.default.red("\u274C Error:"), error instanceof Error ? error.message : String(error)); process.exit(1); } }); program.command("logs [runId]").description("View the deployment logs for your agent").action(async (runId) => { try { await logsCommand(runId); } catch (error) { console.error(import_chalk5.default.red("\u274C Error:"), error instanceof Error ? error.message : String(error)); process.exit(1); } }); program.command("metrics [runId]").description("View the deployment metrics for your agent").action(async (runId) => { try { await metricsCommand(runId); } catch (error) { console.error(import_chalk5.default.red("\u274C Error:"), error instanceof Error ? error.message : String(error)); process.exit(1); } }); program.command("code").description("Run the code agent for your project").action(async () => { try { await codeCommand(); } catch (error) { console.error(import_chalk5.default.red("\u274C Error:"), error instanceof Error ? error.message : String(error)); process.exit(1); } }); if (process.argv.length <= 2) { program.help(); } program.parse(process.argv); //# sourceMappingURL=cli.js.map