@kya-os/cli
Version:
CLI for KYA-OS MCP-I setup and management
167 lines ⢠7.59 kB
JavaScript
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.MCP_IDENTITY_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");
// Try to fetch agent info
if (processVars.MCP_IDENTITY_AGENT_SLUG) {
const agentResponse = await fetch(`https://knowthat.ai/api/agents/${processVars.MCP_IDENTITY_AGENT_SLUG}`);
if (agentResponse.ok) {
spinner.stop();
const agent = (await agentResponse.json());
// Show agent details with Decrypt effect
const agentDetailsText = ` ā ${chalk.green("Agent found in registry")}\n` +
` Name: ${chalk.gray(agent.name)}\n` +
` Status: ${chalk.gray(agent.status)}\n` +
` Profile: ${chalk.cyan(`https://knowthat.ai/agents/${processVars.MCP_IDENTITY_AGENT_SLUG}`)}`;
await cliEffects.showCustomEffect("decrypt", agentDetailsText, {
config: {
duration: 2000,
ciphertextColors: ["00ff00", "00ff80", "80ff00"],
finalColor: "ffffff",
typingSpeed: 2,
},
});
}
else if (agentResponse.status === 404) {
console.log(` ā ${chalk.yellow("Agent not found in registry")}`);
}
}
}
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.MCP_IDENTITY_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.MCP_IDENTITY_AGENT_DID) {
// Show identity summary with Decrypt effect
let summaryText = `\nšÆ Your agent DID: ${chalk.green(processVars.MCP_IDENTITY_AGENT_DID)}`;
if (processVars.MCP_IDENTITY_AGENT_SLUG) {
summaryText += `\nš Agent profile: ${chalk.cyan(`https://knowthat.ai/agents/${processVars.MCP_IDENTITY_AGENT_SLUG}`)}`;
}
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