UNPKG

@kya-os/cli

Version:

CLI for MCP-I setup and management

145 lines • 6.29 kB
import chalk from "chalk"; import ora from "ora"; import { existsSync, readFileSync } from "fs"; import { join } from "path"; import { EnvManager } from "../utils/env-manager.js"; import { detectPlatform } from "../utils/platform-detector.js"; import { showSuccess, showWarning } from "../utils/prompts.js"; import { cliEffects } from "../effects/cli-integration.js"; export async function check(options) { console.log(chalk.cyan("\nšŸ” Checking MCP-I Configuration\n")); const envManager = new EnvManager(); let hasIssues = false; // 1. Check for identity files console.log(chalk.bold("šŸ“ Identity Files:")); const identityFile = join(process.cwd(), ".mcp-identity.json"); const hasIdentityFile = existsSync(identityFile); if (hasIdentityFile) { console.log(` āœ“ ${chalk.green(".mcp-identity.json")} found`); if (options.verbose) { try { const identity = JSON.parse(readFileSync(identityFile, "utf-8")); console.log(` DID: ${chalk.gray(identity.did)}`); console.log(` Agent: ${chalk.gray(identity.agentSlug)}`); console.log(` Registered: ${chalk.gray(identity.registeredAt)}`); } catch (error) { console.log(` ${chalk.red("Error reading file")}`); } } } else { console.log(` āœ— ${chalk.red(".mcp-identity.json")} not found`); hasIssues = true; } // 2. Check environment files console.log(`\n${chalk.bold("šŸ“„ Environment Files:")}`); const platformInfo = detectPlatform(); const envFiles = [".env", ".env.local", ".env.production"]; let foundEnvFile = false; for (const file of envFiles) { if (existsSync(join(process.cwd(), file))) { console.log(` āœ“ ${chalk.green(file)} found`); foundEnvFile = true; if (options.verbose) { const vars = envManager.readEnvFile(file); const { valid, missing } = envManager.validateVariables(vars); if (valid) { console.log(` ${chalk.gray("All required variables present")}`); } else { console.log(` ${chalk.yellow(`Missing: ${missing.join(", ")}`)}`); } } } } if (!foundEnvFile) { console.log(` āœ— ${chalk.red("No environment files found")}`); hasIssues = true; } // 3. Check environment variables console.log(`\n${chalk.bold("šŸ” Environment Variables:")}`); const processVars = envManager.getFromProcess(); const { valid, missing } = envManager.validateVariables(processVars); if (valid) { console.log(` āœ“ ${chalk.green("All required variables set")}`); if (options.verbose) { console.log("\n" + envManager.formatForDisplay(processVars)); } } else { console.log(` āœ— ${chalk.red(`Missing variables: ${missing.join(", ")}`)}`); hasIssues = true; } // 4. Check .gitignore console.log(`\n${chalk.bold("🚫 Git Security:")}`); const sensitiveFiles = [".env", ".env.local", ".mcp-identity.json"]; const { missing: notIgnored } = envManager.checkGitignore(sensitiveFiles); if (notIgnored.length === 0) { console.log(` āœ“ ${chalk.green("All sensitive files in .gitignore")}`); } else { console.log(` āœ— ${chalk.red("Not in .gitignore:")} ${notIgnored.join(", ")}`); console.log(` ${chalk.yellow("Run: npx kya-os init --force to fix")}`); hasIssues = true; } // 5. Test registry connection (if we have identity) if (processVars.AGENT_DID && options.verbose) { console.log(`\n${chalk.bold("🌐 Registry Connection:")}`); const spinner = ora("Testing connection to knowthat.ai...").start(); try { const response = await fetch("https://knowthat.ai/api/health"); if (response.ok) { spinner.succeed("Connected to knowthat.ai"); // Registry connection successful console.log(` āœ“ ${chalk.green("Connected to Know-That-AI registry")}`); console.log(` ${chalk.gray("Use 'mcpi register' to register your agent")}`); console.log(` ${chalk.gray("Use 'mcpi status' to check registration status")}`); } else { spinner.fail("Failed to connect to knowthat.ai"); hasIssues = true; } } catch (error) { spinner.fail("Network error connecting to knowthat.ai"); hasIssues = true; } } // 6. Platform-specific checks console.log(`\n${chalk.bold("šŸš€ Platform Configuration:")}`); console.log(` Platform: ${chalk.cyan(platformInfo.platform)}`); if (platformInfo.platform === "vercel" || platformInfo.platform === "nextjs") { if (!processVars.AGENT_DID) { console.log(` ${chalk.yellow("āš ļø Remember to add environment variables to Vercel Dashboard")}`); console.log(` ${chalk.gray("Run: npx kya-os env copy")}`); } } // Summary console.log(`\n${chalk.bold("šŸ“Š Summary:")}`); if (!hasIssues) { showSuccess("MCP-I is properly configured!"); if (processVars.AGENT_DID) { // Show identity summary with Decrypt effect let summaryText = `\nšŸŽÆ Your agent DID: ${chalk.green(processVars.AGENT_DID)}`; summaryText += `\nšŸ“ Use 'mcpi status' to check registration status`; await cliEffects.showCustomEffect("decrypt", summaryText, { config: { duration: 2500, ciphertextColors: ["008000", "00cb00", "00ff00"], finalColor: "eda000", typingSpeed: 1, useGradient: true, gradientDirection: "horizontal", }, }); } } else { showWarning("Some configuration issues found"); console.log("\nTo fix issues, run:"); console.log(chalk.cyan(" npx kya-os init")); } } //# sourceMappingURL=check.js.map