i-self 0.4.3

Personal developer-companion CLI: scans your repos, indexes code semantically, watches your activity, and moves AI-agent sessions between tools (Claude Code, Aider, Goose, OpenAI Codex CLI, Continue.dev, OpenCode).
use crate::storage::DeveloperProfile;
use colored::Colorize;

pub fn format_profile(profile: &DeveloperProfile) -> String {
    let mut output = String::new();

    output.push_str(&format!("{}\n", "👤 i-self Developer Profile".bold().cyan()));
    output.push_str(&format!("Last updated: {}\n\n", profile.last_updated.format("%Y-%m-%d %H:%M")));

    // Identity
    if profile.identity.name.is_some() || profile.identity.github_username.is_some() {
        output.push_str(&format!("{}\n", "Identity:".bold().underline()));
        if let Some(name) = &profile.identity.name {
            output.push_str(&format!("  Name: {}\n", name));
        }
        if let Some(github) = &profile.identity.github_username {
            output.push_str(&format!("  GitHub: @{}\n", github.cyan()));
        }
        if let Some(email) = &profile.identity.email {
            output.push_str(&format!("  Email: {}\n", email));
        }
        output.push('\n');
    }

    // GitHub Stats
    if profile.github.total_repositories > 0 {
        output.push_str(&format!("{}\n", "📊 GitHub Statistics:".bold().underline()));
        output.push_str(&format!("  Repositories: {}\n", profile.github.total_repositories));
        output.push_str(&format!("  Commits (30d): {}\n", profile.github.total_contributions_30d));
        output.push_str(&format!("  Contribution streak: {} days\n", profile.github.contribution_streak));
        output.push('\n');

        if !profile.github.primary_languages.is_empty() {
            output.push_str(&format!("{}\n", "Top Languages:".bold()));
            for (lang, _) in &profile.github.primary_languages[..5.min(profile.github.primary_languages.len())] {
                output.push_str(&format!("  • {}\n", lang));
            }
            output.push('\n');
        }

        if !profile.github.most_active_repos.is_empty() {
            output.push_str(&format!("{}\n", "Most Active Repositories:".bold()));
            for repo in &profile.github.most_active_repos[..5.min(profile.github.most_active_repos.len())] {
                let lang = repo.language.as_deref().unwrap_or("Unknown");
                output.push_str(&format!("  • {} ({})\n", repo.name.cyan(), lang.dimmed()));
            }
            output.push('\n');
        }
    }

    // Skills
    if !profile.skills.languages.is_empty() {
        output.push_str(&format!("{}\n", "🎯 Skills:".bold().underline()));
        for skill in &profile.skills.languages {
            let bar = create_bar(skill.proficiency_score * 100.0, 15);
            output.push_str(&format!("  {:15} {}\n", skill.name, bar));
        }
        output.push('\n');
    }

    // Work History
    if !profile.work_history.recent_projects.is_empty() {
        output.push_str(&format!("{}\n", "💼 Recent Projects:".bold().underline()));
        for project in &profile.work_history.recent_projects {
            output.push_str(&format!("  • {}\n", project.name.cyan()));
            if let Some(desc) = &project.description {
                output.push_str(&format!("    {}\n", desc.dimmed()));
            }
        }
        output.push('\n');
    }

    output.push_str(&format!("{}\n", "Commands:".bold().underline()));
    output.push_str(&format!("  {} - Refresh your profile\n", "i-self refresh".cyan()));
    output.push_str(&format!("  {} - Query your knowledge\n", "i-self query <question>".cyan()));
    output.push_str(&format!("  {} - Show this status\n", "i-self status".cyan()));

    output
}

fn create_bar(percentage: f64, width: usize) -> String {
    let filled = ((percentage / 100.0) * width as f64) as usize;
    let empty = width - filled;
    
    let filled_str = "â–ˆ".repeat(filled);
    let empty_str = "â–‘".repeat(empty);
    
    format!("[{}{}]", filled_str.green(), empty_str)
}