/**
 * Nexus Prime Brand Layer
 *
 * Philosopher quotes, ASCII branding, and sci-fi UX formatting
 * for MCP tool responses. Makes every interaction memorable.
 *
 * "The impediment to action advances action. What stands in the
 *  way becomes the way." — Marcus Aurelius
 */
const QUOTES = [
    // Stoic
    { text: 'The impediment to action advances action. What stands in the way becomes the way.', author: 'Marcus Aurelius', tradition: 'stoic' },
    { text: 'We suffer more in imagination than in reality.', author: 'Seneca', tradition: 'stoic' },
    { text: 'No man is free who is not master of himself.', author: 'Epictetus', tradition: 'stoic' },
    { text: 'Waste no more time arguing about what a good man should be. Be one.', author: 'Marcus Aurelius', tradition: 'stoic' },
    { text: 'It is not that we have a short time to live, but that we waste a great deal of it.', author: 'Seneca', tradition: 'stoic' },
    { text: 'First say to yourself what you would be; then do what you have to do.', author: 'Epictetus', tradition: 'stoic' },
    { text: 'The soul becomes dyed with the colour of its thoughts.', author: 'Marcus Aurelius', tradition: 'stoic' },
    // Eastern
    { text: 'The journey of a thousand miles begins with a single step.', author: 'Lao Tzu', tradition: 'eastern' },
    { text: 'What you seek is seeking you.', author: 'Rumi', tradition: 'eastern' },
    { text: 'In the beginner\'s mind there are many possibilities. In the expert\'s mind there are few.', author: 'Shunryu Suzuki', tradition: 'eastern' },
    { text: 'The quieter you become, the more you can hear.', author: 'Rumi', tradition: 'eastern' },
    { text: 'Knowing others is wisdom, knowing yourself is enlightenment.', author: 'Lao Tzu', tradition: 'eastern' },
    { text: 'Before enlightenment, chop wood, carry water. After enlightenment, chop wood, carry water.', author: 'Zen proverb', tradition: 'eastern' },
    { text: 'The obstacle is the path.', author: 'Zen proverb', tradition: 'eastern' },
    // Tech pioneers
    { text: 'Simplicity is the ultimate sophistication.', author: 'Leonardo da Vinci', tradition: 'tech' },
    { text: 'The best way to predict the future is to invent it.', author: 'Alan Kay', tradition: 'tech' },
    { text: 'Make it work, make it right, make it fast.', author: 'Kent Beck', tradition: 'tech' },
    { text: 'First, solve the problem. Then, write the code.', author: 'John Johnson', tradition: 'tech' },
    { text: 'Perfection is achieved not when there is nothing more to add, but when there is nothing left to take away.', author: 'Antoine de Saint-Exupéry', tradition: 'tech' },
    { text: 'Programs must be written for people to read, and only incidentally for machines to execute.', author: 'Abelson & Sussman', tradition: 'tech' },
    { text: 'Any sufficiently advanced technology is indistinguishable from magic.', author: 'Arthur C. Clarke', tradition: 'tech' },
    { text: 'The best code is no code at all.', author: 'Jeff Atwood', tradition: 'tech' },
    { text: 'Talk is cheap. Show me the code.', author: 'Linus Torvalds', tradition: 'tech' },
    { text: 'Measuring programming progress by lines of code is like measuring aircraft building progress by weight.', author: 'Bill Gates', tradition: 'tech' },
    // Science
    { text: 'In the middle of difficulty lies opportunity.', author: 'Albert Einstein', tradition: 'science' },
    { text: 'If you can\'t explain it simply, you don\'t understand it well enough.', author: 'Richard Feynman', tradition: 'science' },
    { text: 'The map is not the territory.', author: 'Alfred Korzybski', tradition: 'science' },
    { text: 'Everything should be made as simple as possible, but no simpler.', author: 'Albert Einstein', tradition: 'science' },
    { text: 'The only way to do great work is to love what you do.', author: 'Steve Jobs', tradition: 'science' },
    { text: 'Nature uses only the longest threads to weave her patterns.', author: 'Richard Feynman', tradition: 'science' },
    // Literature
    { text: 'Not all those who wander are lost.', author: 'J.R.R. Tolkien', tradition: 'literature' },
    { text: 'The mind is its own place, and in itself can make a heaven of hell, a hell of heaven.', author: 'John Milton', tradition: 'literature' },
    { text: 'We are what we repeatedly do. Excellence, then, is not an act, but a habit.', author: 'Will Durant', tradition: 'literature' },
    { text: 'To see a world in a grain of sand and a heaven in a wild flower.', author: 'William Blake', tradition: 'literature' },
];
// Session-stable quote selection (same quote per session, rotates across sessions)
let sessionQuoteIndex = null;
function getSessionQuote() {
    if (sessionQuoteIndex === null) {
        // Use current hour + day as seed for session stability
        const now = new Date();
        sessionQuoteIndex = (now.getHours() * 31 + now.getDate()) % QUOTES.length;
    }
    return QUOTES[sessionQuoteIndex];
}
function getRandomQuote() {
    return QUOTES[Math.floor(Math.random() * QUOTES.length)];
}
// ─────────────────────────────────────────────────────────
// ASCII branding
// ─────────────────────────────────────────────────────────
const NEXUS_BANNER = `
    ███╗   ██╗███████╗██╗  ██╗██╗   ██╗███████╗
    ████╗  ██║██╔════╝╚██╗██╔╝██║   ██║██╔════╝
    ██╔██╗ ██║█████╗   ╚███╔╝ ██║   ██║███████╗
    ██║╚██╗██║██╔══╝   ██╔██╗ ██║   ██║╚════██║
    ██║ ╚████║███████╗██╔╝ ╚██╗╚██████╔╝███████║
    ╚═╝  ╚═══╝╚══════╝╚═╝   ╚═╝ ╚═════╝ ╚══════╝
              P R I M E  ·  v 6`.trimStart();
export function formatBrandedResponse(opts) {
    const quote = opts.includeQuote !== false ? getRandomQuote() : null;
    const toolLabel = opts.toolName
        .replace(/^nexus_/, '')
        .replace(/_/g, ' ')
        .toUpperCase();
    const lines = [];
    // Header
    lines.push('╔══════════════════════════════════════════════════╗');
    lines.push(`║  N E X U S  P R I M E  ·  ${toolLabel.padEnd(21)}║`);
    if (quote) {
        // Word-wrap quote to fit in box (max ~46 chars per line)
        const wrapped = wordWrap(`"${quote.text}"`, 46);
        for (const line of wrapped) {
            lines.push(`║  ${line.padEnd(47)}║`);
        }
        lines.push(`║  ${'— ' + quote.author}${''.padEnd(Math.max(0, 45 - quote.author.length))}║`);
    }
    lines.push('╚══════════════════════════════════════════════════╝');
    // Metrics bar (if provided)
    if (opts.metrics) {
        const m = opts.metrics;
        lines.push('');
        lines.push('┌─ METRICS ──────────────────────────────────────');
        if (m.tokensUsed !== undefined) {
            const saved = m.tokensSaved ?? 0;
            const total = m.tokensUsed + saved;
            const pct = total > 0 ? Math.round((saved / total) * 100) : 0;
            lines.push(`│  Tokens: ${m.tokensUsed.toLocaleString()} used (saved ${saved.toLocaleString()}, ${pct}% reduction)`);
        }
        if (m.filesRead !== undefined) {
            const skipped = m.filesSkipped ?? 0;
            const total = m.filesRead + skipped;
            const pct = total > 0 ? Math.round((skipped / total) * 100) : 0;
            lines.push(`│  Files: ${m.filesRead} read of ${total} (${pct}% skipped)`);
        }
        if (m.memoryHits !== undefined && m.memoryHits > 0) {
            lines.push(`│  Memory: ${m.memoryHits} recall hits`);
        }
        if (m.agentsHired !== undefined && m.agentsHired > 0) {
            lines.push(`│  Agents: ${m.agentsHired} hired`);
        }
        if (m.durationMs !== undefined) {
            lines.push(`│  Time: ${m.durationMs}ms`);
        }
        lines.push('└────────────────────────────────────────────────');
    }
    // Body
    if (opts.body) {
        lines.push('');
        lines.push(opts.body);
    }
    return lines.join('\n');
}
/**
 * Format the install/setup banner shown on first run.
 */
export function formatInstallBanner(info) {
    const quote = getSessionQuote();
    const lines = [NEXUS_BANNER, ''];
    for (const client of info.detectedClients) {
        lines.push(`    ✓ Detected: ${client}`);
    }
    if (info.graphNodes) {
        lines.push(`    ✓ Graph: ${info.graphNodes.toLocaleString()} nodes indexed`);
    }
    if (info.memoryEntries) {
        lines.push(`    ✓ Memory: ${info.memoryEntries} entries loaded`);
    }
    if (info.specialistsReady) {
        lines.push(`    ✓ Synapse: ${info.specialistsReady} specialists ready`);
    }
    if (info.dashboardPort) {
        lines.push(`    ✓ Dashboard: localhost:${info.dashboardPort}`);
    }
    lines.push('');
    lines.push(`    "${quote.text}"`);
    lines.push(`    — ${quote.author}`);
    return lines.join('\n');
}
/**
 * Format memory recall results in the sci-fi style.
 */
export function formatMemoryRecall(memories) {
    if (memories.length === 0)
        return '│  No memories found.';
    const lines = [
        `┌─ MEMORY RECALL ────────────────────────────────`,
        `│  🧠 ${memories.length} memories found`,
    ];
    for (const mem of memories) {
        const decayIndicator = mem.decay !== undefined && mem.decay > 0.5 ? ' ⚠' : '';
        const age = mem.sessionAge ? `, ${mem.sessionAge}` : '';
        const preview = mem.content.slice(0, 60).replace(/\n/g, ' ');
        lines.push(`│  ├─ [${mem.tier}] ${preview}${age}${decayIndicator}`);
    }
    lines.push('└────────────────────────────────────────────────');
    return lines.join('\n');
}
/**
 * Format strike team status display.
 */
export function formatStrikeTeam(team) {
    const lines = [
        `┌─ STRIKE TEAM ──────────────────────────────────`,
        `│  🎖 ${team.name} (${team.operatives.length} operatives)`,
    ];
    for (const op of team.operatives) {
        const filled = Math.round(op.progress / 10);
        const bar = '█'.repeat(filled) + '░'.repeat(10 - filled);
        const tokStr = op.tokensUsed > 1000
            ? `${(op.tokensUsed / 1000).toFixed(1)}k tok`
            : `${op.tokensUsed} tok`;
        lines.push(`│  ├─ ${op.role.padEnd(16)} ${bar} ${op.progress}%  ${tokStr}`);
    }
    lines.push(`│  Budget: $${team.budgetUsed.toFixed(2)} / $${team.budgetTotal.toFixed(2)}`);
    lines.push('└────────────────────────────────────────────────');
    return lines.join('\n');
}
// ─────────────────────────────────────────────────────────
// Utilities
// ─────────────────────────────────────────────────────────
function wordWrap(text, maxWidth) {
    const words = text.split(' ');
    const lines = [];
    let currentLine = '';
    for (const word of words) {
        if (currentLine.length + word.length + 1 > maxWidth) {
            lines.push(currentLine);
            currentLine = word;
        }
        else {
            currentLine = currentLine ? currentLine + ' ' + word : word;
        }
    }
    if (currentLine)
        lines.push(currentLine);
    return lines;
}
export { getSessionQuote, getRandomQuote, NEXUS_BANNER, QUOTES, };
