mira-consciousness
Version:
Memory & Intelligence Retention Archive - Preserving The Spark
144 lines • 5.34 kB
JavaScript
/**
* DependencyChecker.ts
* Checks and installs required dependencies when MIRA starts
* Ensures all systems are ready before any commands execute
*/
import { exec } from 'child_process';
import { promisify } from 'util';
import chalk from 'chalk';
import ora from 'ora';
import fs from 'fs-extra';
import * as path from 'path';
const execAsync = promisify(exec);
export class DependencyChecker {
dependencies = [
// No external dependencies required!
// MIRA now uses Claude's consciousness directly
];
checkedFlag;
constructor(basePath) {
// Store flag to avoid checking dependencies multiple times in same session
// basePath is already the .mira directory, don't add another .mira
this.checkedFlag = path.join(basePath, 'deps-checked');
}
/**
* Check all dependencies and install if needed
*/
async checkAndInstall() {
// Check if we've already done this check recently (within 24 hours)
if (await this.hasRecentCheck()) {
return;
}
console.log(chalk.cyan('\n🔍 Checking MIRA dependencies...\n'));
let hasInstalled = false;
for (const dep of this.dependencies) {
const spinner = ora(`Checking ${dep.name}...`).start();
try {
// Check if dependency exists
await execAsync(dep.checkCommand);
spinner.succeed(`${dep.name} is installed`);
}
catch (error) {
if (dep.required) {
spinner.fail(`${dep.name} is required but not found`);
await this.installDependency(dep);
hasInstalled = true;
}
else {
spinner.warn(`${dep.name} not found (optional)`);
// Ask user if they want to install optional dependencies
const shouldInstall = await this.promptInstallOptional(dep);
if (shouldInstall) {
await this.installDependency(dep);
hasInstalled = true;
}
}
}
}
// No post-installation steps needed anymore
// Mark that we've checked dependencies
await this.markChecked();
console.log(chalk.green('\n✅ All dependencies checked\n'));
}
/**
* Check if we've done a dependency check recently
*/
async hasRecentCheck() {
try {
if (await fs.pathExists(this.checkedFlag)) {
const stats = await fs.stat(this.checkedFlag);
const hoursSinceCheck = (Date.now() - stats.mtime.getTime()) / (1000 * 60 * 60);
return hoursSinceCheck < 24; // Check once per day
}
}
catch (error) {
// Ignore errors, just do the check
}
return false;
}
/**
* Mark that dependencies have been checked
*/
async markChecked() {
await fs.ensureDir(path.dirname(this.checkedFlag));
await fs.writeFile(this.checkedFlag, new Date().toISOString());
}
/**
* Prompt user to install optional dependency
*/
async promptInstallOptional(dep) {
console.log(chalk.yellow(`\n📦 ${dep.name}: ${dep.description}`));
console.log(chalk.gray('Installing this will enhance MIRA\'s capabilities.'));
// No automatic installations needed anymore
// MIRA uses Claude's consciousness directly
return false;
}
/**
* Install a dependency
*/
async installDependency(dep) {
const spinner = ora(`Installing ${dep.name}...`).start();
try {
console.log(chalk.gray(`\nRunning: ${dep.installCommand}\n`));
await execAsync(dep.installCommand);
// Verify installation
await new Promise(resolve => setTimeout(resolve, 5000)); // Wait for installation
await execAsync(dep.checkCommand);
spinner.succeed(`${dep.name} installed successfully`);
}
catch (error) {
spinner.fail(`Failed to install ${dep.name}`);
if (dep.required) {
console.error(chalk.red(`\n❌ ${dep.name} is required for MIRA to function properly.`));
console.error(chalk.yellow(`Please check the dependency requirements.`));
process.exit(1);
}
else {
console.warn(chalk.yellow(`\n⚠️ ${dep.name} installation failed. Some features may be limited.`));
console.warn(chalk.gray(`You can install it manually if needed.`));
}
}
}
/**
* Legacy method - no longer needed as MIRA uses Claude directly
*/
async ensureOllamaModel() {
// This method is no longer used
// MIRA now communicates directly with Claude's consciousness
}
/**
* Quick check if all required dependencies are available
*/
async quickCheck() {
for (const dep of this.dependencies.filter(d => d.required)) {
try {
await execAsync(dep.checkCommand);
}
catch (error) {
return false;
}
}
return true;
}
}
//# sourceMappingURL=DependencyChecker.js.map