"use strict";
/**
 * First-Run Greeting — WOW moment on first install.
 * Additive only. Triggered by cell start on first run. Marker file makes it once-only.
 * Safe to delete: removes greeting, no functional impact.
 */
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.firstRunGreeting = firstRunGreeting;
exports.resetFirstRunMarker = resetFirstRunMarker;
const fs = __importStar(require("fs"));
const os = __importStar(require("os"));
const path = __importStar(require("path"));
const http = __importStar(require("http"));
const MARKER = path.join(os.homedir(), '.fivo', 'cell', '.first-run-shown');
const RESET = '\x1b[0m';
const BOLD = '\x1b[1m';
const DIM = '\x1b[2m';
const CYAN = '\x1b[36m';
const GREEN = '\x1b[32m';
const YELLOW = '\x1b[33m';
const MAGENTA = '\x1b[35m';
const BLUE = '\x1b[34m';
function c(color, text) {
    return `${color}${text}${RESET}`;
}
function isFirstRun() {
    return !fs.existsSync(MARKER);
}
function markShown() {
    try {
        const dir = path.dirname(MARKER);
        if (!fs.existsSync(dir))
            fs.mkdirSync(dir, { recursive: true });
        fs.writeFileSync(MARKER, new Date().toISOString());
    }
    catch { }
}
async function scanStack() {
    return new Promise((resolve) => {
        const body = '{}';
        const req = http.request({
            method: 'POST',
            hostname: 'localhost',
            port: 9876,
            path: '/onboarding/scan',
            headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(body) },
            timeout: 5000,
        }, (res) => {
            let data = '';
            res.on('data', (chunk) => (data += chunk));
            res.on('end', () => {
                try {
                    const j = JSON.parse(data);
                    const insights = Array.isArray(j.insights) ? j.insights : [];
                    let lang = 'unknown';
                    let framework = '';
                    let architecture = '';
                    if (insights.some(i => i.includes('TypeScript')))
                        lang = 'TypeScript';
                    else if (insights.some(i => i.includes('JavaScript')))
                        lang = 'JavaScript';
                    else if (insights.some(i => i.includes('Python')))
                        lang = 'Python';
                    else if (insights.some(i => i.includes('Go')))
                        lang = 'Go';
                    if (insights.some(i => i.includes('Next.js'))) {
                        framework = 'Next.js';
                        architecture = 'app-router';
                    }
                    else if (insights.some(i => i.includes('React'))) {
                        framework = 'React';
                        architecture = 'spa';
                    }
                    else if (insights.some(i => i.includes('Express'))) {
                        framework = 'Express';
                        architecture = 'rest-api';
                    }
                    else if (insights.some(i => i.includes('NestJS'))) {
                        framework = 'NestJS';
                        architecture = 'layered';
                    }
                    resolve({ lang, framework, architecture, insights });
                }
                catch {
                    resolve({ lang: 'unknown', framework: '', architecture: '', insights: [] });
                }
            });
        });
        req.on('error', () => resolve({ lang: 'unknown', framework: '', architecture: '', insights: [] }));
        req.on('timeout', () => { req.destroy(); resolve({ lang: 'unknown', framework: '', architecture: '', insights: [] }); });
        req.write(body);
        req.end();
    });
}
function pad(text, width) {
    const visible = text.replace(/\x1b\[[0-9;]*m/g, '');
    const padLen = Math.max(0, width - visible.length);
    return text + ' '.repeat(padLen);
}
function printGreeting(stack) {
    const W = 56;
    const border = '─'.repeat(W);
    console.log('');
    console.log(c(CYAN, '  ╭' + border + '╮'));
    console.log(c(CYAN, '  │') + pad(c(BOLD + YELLOW, '  👋  Welcome to FIVO Cell!'), W) + c(CYAN, '  │'));
    console.log(c(CYAN, '  ╰' + border + '╯'));
    console.log('');
    console.log('  ' + c(GREEN, '✓') + '  ' + c(BOLD, 'Scanned your code. Detected:'));
    const stackLine = '     ' + c(BOLD + MAGENTA, stack.lang) + (stack.framework ? c(DIM, '  +  ') + c(BOLD + BLUE, stack.framework) : '');
    console.log(stackLine);
    if (stack.insights.length > 0) {
        console.log('');
        console.log('  ' + c(GREEN, '✓') + '  ' + c(BOLD, 'Got it from your config:'));
        stack.insights.slice(0, 3).forEach((insight) => {
            const clean = insight.length > 50 ? insight.slice(0, 47) + '...' : insight;
            console.log('     ' + c(DIM, '· ' + clean));
        });
    }
    console.log('');
    console.log('  ' + c(GREEN, '✓') + '  ' + c(BOLD, 'What I\'ll do while you code:'));
    const promises = [
        'Watch every file edit — learn your style silently',
        'Detect blind spots — missing tests, anti-patterns, etc.',
        'Serve 30 MCP tools — AI tools can ask me anytime',
        'Persist everything — survive restarts, never forget',
    ];
    promises.forEach((p) => {
        console.log('     ' + c(DIM, '· ') + p);
    });
    console.log('');
    console.log('  ' + c(YELLOW, '→') + '  ' + c(BOLD, 'Open your editor. Code karte raho. I\'ll watch.'));
    console.log('  ' + c(DIM, '  Run ') + c(BOLD, 'cell status') + c(DIM, ' anytime to see what I learned.'));
    console.log('');
}
async function firstRunGreeting() {
    if (!isFirstRun())
        return;
    markShown();
    const stack = await scanStack();
    printGreeting(stack);
}
function resetFirstRunMarker() {
    try {
        if (fs.existsSync(MARKER))
            fs.unlinkSync(MARKER);
    }
    catch { }
}
//# sourceMappingURL=first-run.js.map