UNPKG

@kya-os/cli

Version:

CLI for MCP-I setup and management

584 lines (583 loc) • 23.6 kB
/** * Demo Command * Consolidated demos for KYA-OS CLI features */ import { Command } from "commander"; import chalk from "chalk"; import inquirer from "inquirer"; import ora from "ora"; import { cliEffects, showPrivateKeyDeleteEffect, showAgentIdentityCreateEffect, showDIDGenerationEffect, getAllEffects, } from "../effects/index.js"; import { createAgentTableWithAvatar, createClaimTable, createWelcomeBanner, createGradientBox, createSuccessBox, createInfoBox, } from "../components/index.js"; import { showScreen } from "../utils/screen-manager.js"; /** * Simulated delay for realistic timing */ const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); /** * Simulate typing effect */ async function simulateTyping(text, delayMs = 50) { for (const char of text) { process.stdout.write(char); await delay(delayMs); } process.stdout.write("\n"); } /** * Demo: Full init experience (1:1 with production) */ async function demoInitExperience(options) { const speedMultiplier = options.fast ? 0.3 : 1; const d = (ms) => delay(ms * speedMultiplier); // Detect package manager (simulating production behavior) const packageManager = process.env.npm_config_user_agent?.includes("yarn") ? "yarn" : process.env.npm_config_user_agent?.includes("pnpm") ? "pnpm" : "npm"; try { // Clear screen and show welcome banner console.clear(); try { const banner = await createWelcomeBanner("KYA-OS"); console.log(banner); } catch (err) { console.log(chalk.bold.cyan("\nšŸš€ MCP-I Initialization\n")); } await d(1000); // Show command console.log(chalk.gray("$ ") + chalk.white("npx @kya-os/cli init")); await d(1500); // Initial loading (simplified for demo to avoid terminal-image issues) await d(2000); // Project detection console.log(chalk.cyan("\nšŸ“ Analyzing project structure...\n")); await d(1000); console.log(chalk.green("āœ“") + " Detected: Next.js project"); console.log(chalk.green("āœ“") + " Found: package.json"); console.log(chalk.green("āœ“") + " No existing KYA-OS configuration"); await d(1500); // Configuration prompts console.log(chalk.bold("\nšŸ”§ Configuration\n")); await simulateTyping(chalk.cyan("? ") + chalk.white("What's your agent name? ") + chalk.gray("(My Cool Agent) ") + chalk.green("AutomationBot-X1"), 30 * speedMultiplier); await d(300); await simulateTyping(chalk.cyan("? ") + chalk.white("Description? ") + chalk.gray("(An agent that...) ") + chalk.green("AI assistant for code review and testing"), 30 * speedMultiplier); await d(300); await simulateTyping(chalk.cyan("? ") + chalk.white("Repository URL? ") + chalk.gray("(https://github.com/...) ") + chalk.green("https://github.com/acme/automation-bot"), 30 * speedMultiplier); await d(300); // NOW GO STRAIGHT TO BLACKHOLE (matching production) console.clear(); await cliEffects.showCustomEffect("blackhole", `šŸ” ${chalk.bold("Creating Agent Identity")}\n\n` + `${chalk.gray("Generating cryptographic identity...")}`, { config: { duration: 5000 * speedMultiplier, blackholeColor: "ffffff", starColors: [ "4a4a4d", "808080", "a0a0a0", "c0c0c0", "e0e0e0", "ffffff", ], finalColor: "00ff00", useGradient: true, gradientDirection: "diagonal", blackholeSize: 0.3, }, persistent: true, skipExitPrompt: true, }); // Simulate registration happening in background await d(1000); // 1. Claim Your Agent screen (matching production) const claimUrl = "https://knowthat.ai/agents/claim?did=did%3Aweb%3Aknowthat.ai%3Aagents%3AAutomationBot-X1&timestamp=1749529436951&signature=ecpYZxbyD6i4BUmv7K0j6A5%2Bpb%2FFn7KRxZG1lQrzPIizylD02XjIXLI0e2fTz25YMsIy6dgSPdz%2FmlNLvsAiAg%3D%3D"; // CLEAN TRANSITION: From blackhole to claim interface console.clear(); // Simple transition message console.log(chalk.cyan("\nInitializing agent claiming protocol...\n")); await d(800 * speedMultiplier); // Draw down the clean claim card (no more broken ASCII) const { createClaimDrawDown } = await import("../components/claim-experience.js"); for await (const frame of createClaimDrawDown(claimUrl)) { console.clear(); console.log(frame); await d(150 * speedMultiplier); // Slightly slower for better effect } await new Promise((resolve) => { process.stdin.once("data", resolve); process.stdin.resume(); }); process.stdin.pause(); // Simulate opening browser console.log(chalk.gray("Opening browser...")); await d(1000); // Simulate polling for claim (matching production) const pollSpinner = ora("Waiting for agent claim... (5:00 remaining)").start(); await d(3000 * speedMultiplier); pollSpinner.text = "Waiting for agent claim... (4:57 remaining)"; await d(1000 * speedMultiplier); pollSpinner.text = "Waiting for agent claim... (4:55 remaining)"; await d(1000 * speedMultiplier); pollSpinner.succeed("āœ… Agent claimed successfully!"); await d(500); // 2. SIMPLE SUCCESS MESSAGE console.clear(); console.log(chalk.green(` ╭─────────────────────────────────────────────────────────────────╮ │ │ │ AUTHORIZATION SUCCESSFUL │ │ │ │ Agent identity has been claimed and is now active. │ │ │ │ Agent: AutomationBot-X1 │ │ Status: READY FOR OPERATION │ │ │ ╰─────────────────────────────────────────────────────────────────╯ `)); await new Promise((resolve) => { process.stdin.once("data", resolve); process.stdin.resume(); }); process.stdin.pause(); // Show environment file creation (matches production) console.log(`\nšŸ“„ ${chalk.bold("Creating environment files...")}`); await d(1000); console.log(` āœ“ Created ${chalk.green(".env.local")}`); console.log(` āœ“ Added to ${chalk.green(".gitignore")}: .env.local, .mcp-identity.json`); await d(1500); // 3. Combined Environment Configuration & Success screen const envConfigContent = [ "šŸ“ Created files:", "", " • .env.local (for local development)", " • Added to .gitignore automatically", ]; const combinedScreen = `${createGradientBox(envConfigContent, { title: "Environment Configuration", gradientStyle: "cool", })} ${createSuccessBox("MCP-I initialization complete!", "Your AI agent now has a verifiable decentralized identity on the KYA-OS network.")}`; await showScreen(combinedScreen, { requireInput: true, clearBefore: true, prompt: "Press Enter to continue...", }); // 4. Integration Guide (with proper exit) const integrationContent = [ "Next Steps: ", "", "1. Install the MCP-I package:", ` ${chalk.cyan(`${packageManager} ${packageManager === "npm" ? "install" : "add"} @kya-os/mcp-i`)}`, "", "2. Add to your code:", ` ${chalk.cyan('import "@kya-os/mcp-i/auto"')}`, "", "3. For production deployment:", " • Go to Vercel Dashboard → Settings → Environment Variables", " • Add all MCP_IDENTITY_* variables from .env.local", ` • Run: ${chalk.cyan("npx kya-os env copy")} to copy them to clipboard`, ]; await showScreen(createGradientBox(integrationContent, { title: "Integration Guide", gradientStyle: "cool", }), { requireInput: true, // Changed to true to match production clearBefore: true, prompt: "Press Enter to exit...", // Proper exit prompt }); } catch (error) { if (error instanceof Error && error.message.includes("prompt")) { console.log(chalk.gray("\n\nDemo cancelled.\n")); } else { console.error(chalk.red("Error:"), error); } } } /** * Demo: UI Components showcase */ async function demoUIComponents() { console.clear(); // Welcome banner try { const banner = await createWelcomeBanner("UI Demo"); console.log(banner); } catch (err) { console.log(chalk.bold.cyan("\nšŸŽØ UI Components Showcase\n")); } await delay(1500); // Generate random DID components for variety const generateRandomDID = () => { const domains = [ "agents.ai", "knowthat.ai", "cyberpunk.dev", "neural.net", "quantum.tech", ]; const names = [ "CyberAgent", "NeuralBot", "QuantumAI", "SynthMind", "CodeForge", "DataVault", "LogicCore", "ByteGuard", ]; const numbers = Math.floor(Math.random() * 999) + 1; const suffixes = [ "X", "Pro", "Max", "Prime", "Neo", "Alpha", "Beta", "Omega", ]; const domain = domains[Math.floor(Math.random() * domains.length)]; const name = names[Math.floor(Math.random() * names.length)]; const suffix = suffixes[Math.floor(Math.random() * suffixes.length)]; return `did:web:${domain}:agents:${name}-${suffix}${numbers}`; }; // Agent progression showcase - multiple agents at different levels console.log(chalk.bold("\nšŸ¤– CYBERPUNK AVATAR PROGRESSION\n")); console.log(chalk.gray("Each DID generates a unique, deterministic cyberpunk avatar\n")); // Level 0: Unclaimed Agent (Dark, single shape) console.log(chalk.bold("šŸ“Š Level 0 - Unclaimed Agent (Dark & Minimal):\n")); const unclaimedDID = generateRandomDID(); const unclaimedTable = await createAgentTableWithAvatar({ name: "DormantAgent", description: "Unclaimed agent in dormant state", did: unclaimedDID, agentSlug: "dormant-agent", }, { claimed: false, // Level 0: Dark gray, single shape hasDescription: true, }); console.log(unclaimedTable); console.log(chalk.gray(`šŸ”— DID: ${unclaimedDID}\n`)); await delay(2000); // Level 2: Verified Agent (Cyan/teal with gradient) console.log(chalk.bold("šŸ“Š Level 2 - Verified Agent (Cyan Gradients):\n")); const verifiedDID = generateRandomDID(); const verifiedTable = await createAgentTableWithAvatar({ name: "VerifiedBot-Pro", description: "Verified agent with enhanced security features", did: verifiedDID, agentSlug: "verified-bot-pro", }, { claimed: true, // +1 verified: true, // +1 = Level 2: Cyan/teal with gradients hasDescription: true, }); console.log(verifiedTable); console.log(chalk.gray(`šŸ”— DID: ${verifiedDID}\n`)); await delay(2000); // Level 3: Enhanced Agent (Purple/magenta with 3 shapes) console.log(chalk.bold("šŸ“Š Level 3 - Enhanced Agent (Purple Power):\n")); const enhancedDID = generateRandomDID(); const enhancedTable = await createAgentTableWithAvatar({ name: "EnhancedMind-X9", description: "Advanced agent with GitHub integration and enhanced capabilities", did: enhancedDID, agentSlug: "enhanced-mind-x9", }, { claimed: true, // +1 verified: true, // +1 hasGithub: true, // +1 = Level 3: Purple/magenta with 3 shapes hasDescription: true, }); console.log(enhancedTable); console.log(chalk.gray(`šŸ”— DID: ${enhancedDID}\n`)); await delay(2000); // Level 4: Complete Agent (Rainbow/multi-color, full complexity) console.log(chalk.bold("šŸ“Š Level 4 - Complete Agent (Rainbow Mastery):\n")); const completeDID = generateRandomDID(); const completeTable = await createAgentTableWithAvatar({ name: "OmegaMind-Ultimate", description: "Fully evolved agent with complete handshake protocol", did: completeDID, agentSlug: "omega-mind-ultimate", }, { claimed: true, // +1 verified: true, // +1 hasGithub: true, // +1 hasDescription: true, // +1 handshakeComplete: true, // +1 = Level 4: Rainbow/multi-color, max complexity }); console.log(completeTable); console.log(chalk.gray(`šŸ”— DID: ${completeDID}\n`)); await delay(2000); // Show the deterministic nature console.log(chalk.bold("\nšŸ”„ DETERMINISTIC DEMO:\n")); console.log(chalk.yellow("Same DID = Same Avatar (deterministic)")); console.log(chalk.gray("Generating the same agent twice...\n")); const sameDID = "did:web:demo.ai:agents:DeterministicBot-42"; console.log(chalk.bold("First generation:")); const firstGen = await createAgentTableWithAvatar({ name: "DeterministicBot", description: "This agent will look identical when regenerated", did: sameDID, agentSlug: "deterministic-bot", }, { claimed: true, verified: true, hasDescription: true, }); console.log(firstGen); await delay(1500); console.log(chalk.bold("Second generation (same DID):")); const secondGen = await createAgentTableWithAvatar({ name: "DeterministicBot", description: "This agent will look identical when regenerated", did: sameDID, // Same DID = Same avatar agentSlug: "deterministic-bot", }, { claimed: true, verified: true, hasDescription: true, }); console.log(secondGen); console.log(chalk.green("āœ… Identical avatars! Same DID = Same cyberpunk pattern\n")); await delay(2000); // Show other UI components console.log(chalk.bold("\nšŸ”— Claim URL Display:\n")); const claimTable = createClaimTable({ claimUrl: `https://knowthat.ai/agents/claim?did=${encodeURIComponent(completeDID)}&timestamp=1749529436951&signature=demo`, }); console.log(claimTable); await delay(1500); // Gradient boxes console.log(chalk.bold("\n🌈 Gradient Boxes:\n")); const coolBox = createGradientBox("This is a cool gradient box\nwith multiple lines of text", { title: "Cool Style", gradientStyle: "cool" }); console.log(coolBox); console.log(""); const rainbowBox = createGradientBox("Rainbow gradient for special messages!", { title: "Rainbow Style", gradientStyle: "rainbow" }); console.log(rainbowBox); console.log(""); const warmBox = createGradientBox("Warm gradient for special messages!", { title: "Warm Style", gradientStyle: "warm", }); console.log(warmBox); console.log(""); await delay(1500); // Status boxes console.log(chalk.bold("\nšŸ“¦ Status Boxes:\n")); const successBox = createSuccessBox("Cyberpunk avatars generated successfully!", `Generated ${4} unique agent identities with deterministic avatars.`); console.log(successBox); console.log(""); const infoBox = createInfoBox("Avatar System Info", "Each DID creates a unique geometric pattern using SHA-256 deterministic seeding."); console.log(infoBox); console.log(""); await delay(2000); console.log(chalk.bold.green("\nāœ… UI Components showcase complete!")); console.log(chalk.gray("Run again to see different random DIDs generate new avatars!\n")); } /** * Demo: Terminal effects showcase */ async function demoEffects() { const effects = getAllEffects(); console.clear(); console.log(chalk.bold.cyan("\n✨ Terminal Effects Showcase\n")); console.log(chalk.gray("Demonstrating all available effects...\n")); await delay(1500); for (const effectEntry of effects) { console.log(chalk.magenta(`\nšŸ“ŗ Demonstrating: ${effectEntry.name}\n`)); await delay(1000); // Custom configurations for each effect let config = {}; switch (effectEntry.name) { case "burn": config = { duration: 3000, flameColors: ["ff0000", "ff6600", "ffcc00", "ffffff"], flameHeight: 0.7, turbulence: 0.8, }; break; case "decrypt": config = { duration: 2500, typingSpeed: 2, ciphertextColors: ["008000", "00cb00", "00ff00"], finalColor: "eda000", }; break; case "blackhole": config = { duration: 4000, blackholeColor: "ffffff", starColors: [ "ffcc0d", "ff7326", "ff194d", "bf2669", "702a8c", "049dbf", ], finalColor: "00ff00", }; break; case "beams": config = { duration: 3000, beamCount: 8, beamColors: ["00ff00", "00ffff", "ffffff"], beamSpeed: 2.0, }; break; case "waves": config = { duration: 2500, waveColors: ["0080ff", "00ffff", "ffffff"], waveSpeed: 1.5, }; break; } await cliEffects.showCustomEffect(effectEntry.name, `✨ ${effectEntry.description}\n\n` + `Effect: ${effectEntry.name.toUpperCase()}\n` + `━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n` + `Demonstrating the ${effectEntry.name} effect`, { config, skipExitPrompt: true }); await delay(1500); } console.log(chalk.bold.green("\nāœ… Effects showcase complete!\n")); } /** * Demo: Interactive menu */ async function demoInteractive() { console.clear(); try { const banner = await createWelcomeBanner("KYA-OS"); console.log(banner); } catch (err) { console.log(chalk.bold.cyan("\nšŸš€ KYA-OS CLI Demos\n")); } const { demo } = await inquirer.prompt([ { type: "list", name: "demo", message: "Choose a demo to run:", choices: [ { name: "šŸš€ Init Experience - See the full init command flow", value: "init", }, { name: "šŸŽØ UI Components - Explore tables, boxes, and gradients", value: "ui", }, { name: "✨ Terminal Effects - Watch all animation effects", value: "effects", }, { name: "šŸ”‘ Security Scenarios - Key deletion and identity creation", value: "security", }, { name: "āŒ Exit", value: "exit" }, ], }, ]); switch (demo) { case "init": await demoInitExperience({ fast: false }); break; case "ui": await demoUIComponents(); break; case "effects": await demoEffects(); break; case "security": console.log(chalk.yellow("\nšŸ” Security Scenarios\n")); await delay(1000); console.log(chalk.cyan("1. Private Key Deletion:\n")); await showPrivateKeyDeleteEffect("agent-key-compromised-2024", true); await delay(2000); console.log(chalk.cyan("\n2. Agent Identity Creation:\n")); await showAgentIdentityCreateEffect("SecureAgent-001", true); await delay(1000); await showDIDGenerationEffect("did:kya:z6Mkf5rGMoatrSj1f4CgPrHknGZ", true); break; case "exit": console.log(chalk.gray("\nExiting demo...\n")); return; } // Ask if they want to run another demo const { again } = await inquirer.prompt([ { type: "confirm", name: "again", message: "\nWould you like to run another demo?", default: true, }, ]); if (again) { await demoInteractive(); } } /** * Create the demo command */ export function createDemoCommand() { const command = new Command("demo") .description("Run KYA-OS CLI demos") .option("-i, --init", "Run the init experience demo") .option("-u, --ui", "Run the UI components demo") .option("-e, --effects", "Run the terminal effects demo") .option("-s, --security", "Run the security scenarios demo") .option("-f, --fast", "Run demos at increased speed") .action(async (options) => { // If no specific demo is selected, show interactive menu if (!options.init && !options.ui && !options.effects && !options.security) { await demoInteractive(); return; } // Run specific demos based on flags if (options.init) { await demoInitExperience({ fast: options.fast }); } if (options.ui) { await demoUIComponents(); } if (options.effects) { await demoEffects(); } if (options.security) { console.log(chalk.yellow("\nšŸ” Security Scenarios\n")); await delay(1000); console.log(chalk.cyan("1. Private Key Deletion:\n")); await showPrivateKeyDeleteEffect("agent-key-compromised-2024", true); await delay(2000); console.log(chalk.cyan("\n2. Agent Identity Creation:\n")); await showAgentIdentityCreateEffect("SecureAgent-001", true); await delay(1000); await showDIDGenerationEffect("did:kya:z6Mkf5rGMoatrSj1f4CgPrHknGZ", true); } }); return command; } //# sourceMappingURL=demo.js.map