/** * Initialize NeoHub configuration */ import inquirer from 'inquirer'; import chalk from 'chalk'; import ora from 'ora'; import { OllamaClient } from '@fsfalmansour/neohub-core'; import { ConfigManager } from '../config'; export async function initCommand(): Promise { console.log(chalk.bold.cyan('\nšŸš€ NeoHub Setup\n')); const config = new ConfigManager(); // Ollama URL const { ollamaUrl } = await inquirer.prompt<{ ollamaUrl: string }>([ { type: 'input', name: 'ollamaUrl', message: 'Ollama API URL:', default: 'http://localhost:11434', }, ]); // Test connection const spinner = ora('Testing connection to Ollama...').start(); const client = new OllamaClient({ baseUrl: ollamaUrl }); try { const isHealthy = await client.healthCheck(); if (!isHealthy) { spinner.fail(chalk.red('Cannot connect to Ollama')); console.log(chalk.yellow('\nPlease ensure Ollama is running and try again.')); return; } // Get available models const modelsResponse = await client.listModels(); spinner.succeed(chalk.green('Connected to Ollama')); const modelChoices = modelsResponse.models.map(m => ({ name: `${m.name} (${(m.size / 1024 / 1024 / 1024).toFixed(2)} GB)`, value: m.name, })); if (modelChoices.length === 0) { console.log(chalk.yellow('\nNo models found. Please pull a model first:')); console.log(chalk.gray(' ollama pull deepseek-coder:33b')); console.log(chalk.gray(' ollama pull codellama:34b')); return; } // Select model const { model } = await inquirer.prompt<{ model: string }>([ { type: 'list', name: 'model', message: 'Select default model:', choices: modelChoices, }, ]); // Preferences const { autoContext } = await inquirer.prompt<{ autoContext: boolean }>([ { type: 'confirm', name: 'autoContext', message: 'Automatically include file context in conversations?', default: true, }, ]); // Save configuration config.setOllamaConfig({ baseUrl: ollamaUrl, model }); config.setPreference('autoContext', autoContext); console.log(chalk.bold.green('\nāœ“ Configuration saved!\n')); console.log(chalk.gray('Config location: ' + config.getConfigPath())); console.log(chalk.gray('\nYou can now use NeoHub:')); console.log(chalk.cyan(' neohub chat') + chalk.gray(' - Start a chat session')); console.log(chalk.cyan(' neohub edit') + chalk.gray(' - Edit code with AI')); console.log(chalk.cyan(' neohub analyze') + chalk.gray(' - Analyze code\n')); } catch (error) { spinner.fail(chalk.red('Setup failed: ' + (error as Error).message)); } }