/**
 * CLI Enhancements
 *
 * Features:
 * 8. Debug Command - session/model/hooks/plugins/mcp/performance info
 * 9. Company Announcements - priority-based announcement system
 * 10. Attribution Customization - commit/PR footer branding
 * 11. PR Status Indicator - prompt indicator for PR status
 * 12. Max Turns Flag - configurable turn limits
 * 13. No Session Persistence Flag - ephemeral session mode
 * 14. History Bash Autocomplete - command history and prefix completion
 * 15. Strict MCP Config Flag - restrict MCP servers
 * 16. Prompt Stash (Ctrl+S) - save/restore prompt drafts
 */
import { logger } from '../utils/logger.js';
export class DebugCommand {
    constructor() { }
    getDebugInfo() {
        return {
            session: { id: 'none', messageCount: 0, tokenUsage: 0 },
            model: { name: 'unknown', provider: 'unknown', contextWindow: 0 },
            hooks: { registered: 0, fired: 0, errors: 0 },
            plugins: { loaded: 0, active: 0 },
            mcp: { servers: 0, connected: 0 },
            performance: { avgResponseMs: 0, totalCost: 0 },
        };
    }
    formatDebugOutput(info) {
        const lines = [
            '=== Debug Info ===',
            '',
            '[Session]',
            `  ID: ${info.session.id}`,
            `  Messages: ${info.session.messageCount}`,
            `  Token Usage: ${info.session.tokenUsage}`,
            '',
            '[Model]',
            `  Name: ${info.model.name}`,
            `  Provider: ${info.model.provider}`,
            `  Context Window: ${info.model.contextWindow}`,
            '',
            '[Hooks]',
            `  Registered: ${info.hooks.registered}`,
            `  Fired: ${info.hooks.fired}`,
            `  Errors: ${info.hooks.errors}`,
            '',
            '[Plugins]',
            `  Loaded: ${info.plugins.loaded}`,
            `  Active: ${info.plugins.active}`,
            '',
            '[MCP]',
            `  Servers: ${info.mcp.servers}`,
            `  Connected: ${info.mcp.connected}`,
            '',
            '[Performance]',
            `  Avg Response: ${info.performance.avgResponseMs}ms`,
            `  Total Cost: $${info.performance.totalCost.toFixed(4)}`,
        ];
        return lines.join('\n');
    }
    parseFilter(filter) {
        const parts = filter.split(',').map(s => s.trim()).filter(Boolean);
        const include = [];
        const exclude = [];
        for (const part of parts) {
            if (part.startsWith('!')) {
                exclude.push(part.slice(1));
            }
            else {
                include.push(part);
            }
        }
        return { include, exclude };
    }
    filterCategories(info, filter) {
        const { include, exclude } = this.parseFilter(filter);
        const allKeys = Object.keys(info);
        const result = {};
        for (const key of allKeys) {
            if (exclude.includes(key))
                continue;
            if (include.length > 0 && !include.includes(key))
                continue;
            result[key] = info[key];
        }
        return result;
    }
}
export class AnnouncementManager {
    announcements = [];
    dismissed = new Set();
    constructor() { }
    addAnnouncement(message, priority = 'info', options) {
        const announcement = {
            id: options?.id ?? `ann-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
            message,
            priority,
            expiresAt: options?.expiresAt,
            dismissible: options?.dismissible ?? true,
        };
        this.announcements.push(announcement);
        logger.info(`Announcement added: ${announcement.id}`);
        return announcement;
    }
    getActiveAnnouncements() {
        const now = Date.now();
        return this.announcements.filter(a => {
            if (this.dismissed.has(a.id))
                return false;
            if (a.expiresAt && a.expiresAt < now)
                return false;
            return true;
        });
    }
    dismiss(id) {
        const ann = this.announcements.find(a => a.id === id);
        if (!ann)
            return false;
        if (!ann.dismissible)
            return false;
        this.dismissed.add(id);
        return true;
    }
    clearExpired() {
        const now = Date.now();
        const before = this.announcements.length;
        this.announcements = this.announcements.filter(a => !a.expiresAt || a.expiresAt >= now);
        return before - this.announcements.length;
    }
    formatAnnouncements() {
        const active = this.getActiveAnnouncements();
        if (active.length === 0)
            return '';
        const priorityOrder = { critical: 0, warning: 1, info: 2 };
        const sorted = [...active].sort((a, b) => priorityOrder[a.priority] - priorityOrder[b.priority]);
        return sorted.map(a => {
            const prefix = a.priority === 'critical' ? '[!]' : a.priority === 'warning' ? '[*]' : '[i]';
            return `${prefix} ${a.message}`;
        }).join('\n');
    }
    getCount() {
        return this.getActiveAnnouncements().length;
    }
}
const DEFAULT_ATTRIBUTION = {
    commitFooter: 'Co-Authored-By: Code Buddy <noreply@codebuddy.dev>',
    prFooter: 'Generated with Code Buddy',
    enabled: true,
};
export class AttributionManager {
    config;
    constructor(config) {
        this.config = { ...DEFAULT_ATTRIBUTION, ...config };
    }
    getCommitFooter() {
        if (!this.config.enabled)
            return '';
        return this.config.commitFooter;
    }
    getPRFooter() {
        if (!this.config.enabled)
            return '';
        return this.config.prFooter;
    }
    setCommitFooter(footer) {
        this.config.commitFooter = footer;
    }
    setPRFooter(footer) {
        this.config.prFooter = footer;
    }
    formatCommitMessage(message) {
        if (!this.config.enabled)
            return message;
        const footer = this.getCommitFooter();
        if (!footer)
            return message;
        return `${message}\n\n${footer}`;
    }
    formatPRBody(body) {
        if (!this.config.enabled)
            return body;
        const footer = this.getPRFooter();
        if (!footer)
            return body;
        return `${body}\n\n${footer}`;
    }
    isEnabled() {
        return this.config.enabled;
    }
    setEnabled(enabled) {
        this.config.enabled = enabled;
    }
    getConfig() {
        return { ...this.config };
    }
}
const STATUS_ICONS = {
    draft: 'o',
    pending: '?',
    approved: '+',
    'changes-requested': '!',
    merged: 'M',
    closed: 'X',
};
const STATUS_COLORS = {
    draft: 'gray',
    pending: 'yellow',
    approved: 'green',
    'changes-requested': 'red',
    merged: 'purple',
    closed: 'red',
};
export class PRStatusIndicator {
    currentPR = null;
    constructor() { }
    setPR(info) {
        this.currentPR = info;
    }
    getPR() {
        return this.currentPR;
    }
    getStatusIcon(status) {
        return STATUS_ICONS[status] ?? '?';
    }
    getStatusColor(status) {
        return STATUS_COLORS[status] ?? 'white';
    }
    formatPromptIndicator() {
        if (!this.currentPR)
            return '';
        const icon = this.getStatusIcon(this.currentPR.status);
        const { passed, failed, pending } = this.currentPR.checks;
        return `[${icon} PR#${this.currentPR.number} ${passed}/${passed + failed + pending}]`;
    }
    clearPR() {
        this.currentPR = null;
    }
    hasPR() {
        return this.currentPR !== null;
    }
}
// ============================================================================
// 12. Max Turns Flag
// ============================================================================
export class MaxTurnsManager {
    maxTurns;
    currentTurn = 0;
    constructor(maxTurns) {
        this.maxTurns = maxTurns ?? null;
    }
    increment() {
        this.currentTurn++;
    }
    hasReachedLimit() {
        if (this.maxTurns === null)
            return false;
        return this.currentTurn >= this.maxTurns;
    }
    getRemainingTurns() {
        if (this.maxTurns === null)
            return null;
        return Math.max(0, this.maxTurns - this.currentTurn);
    }
    getCurrentTurn() {
        return this.currentTurn;
    }
    getMaxTurns() {
        return this.maxTurns;
    }
    setMaxTurns(max) {
        this.maxTurns = max;
    }
    reset() {
        this.currentTurn = 0;
    }
    formatStatus() {
        if (this.maxTurns === null) {
            return `Turn ${this.currentTurn} (unlimited)`;
        }
        return `Turn ${this.currentTurn}/${this.maxTurns}`;
    }
}
// ============================================================================
// 13. No Session Persistence Flag
// ============================================================================
export class SessionPersistenceConfig {
    persistenceEnabled;
    constructor(enabled) {
        this.persistenceEnabled = enabled ?? true;
    }
    isEnabled() {
        return this.persistenceEnabled;
    }
    setEnabled(enabled) {
        this.persistenceEnabled = enabled;
    }
    shouldSave() {
        return this.persistenceEnabled;
    }
    shouldLoad() {
        return this.persistenceEnabled;
    }
    getMode() {
        return this.persistenceEnabled ? 'persistent' : 'ephemeral';
    }
}
// ============================================================================
// 14. History Bash Autocomplete
// ============================================================================
export class BashHistoryAutocomplete {
    history = [];
    maxHistory;
    constructor(maxHistory) {
        this.maxHistory = maxHistory ?? 1000;
    }
    addCommand(command) {
        const trimmed = command.trim();
        if (!trimmed)
            return;
        // Remove duplicate if it exists
        const existingIndex = this.history.indexOf(trimmed);
        if (existingIndex !== -1) {
            this.history.splice(existingIndex, 1);
        }
        this.history.push(trimmed);
        // Enforce max history
        if (this.history.length > this.maxHistory) {
            this.history = this.history.slice(-this.maxHistory);
        }
    }
    getCompletions(prefix) {
        if (!prefix)
            return [];
        return this.history.filter(cmd => cmd.startsWith(prefix));
    }
    loadFromFile(historyFilePath) {
        // Simulated load - returns 0 for non-existent files
        logger.info(`Loading history from: ${historyFilePath}`);
        return 0;
    }
    getHistory() {
        return [...this.history];
    }
    clearHistory() {
        this.history = [];
    }
    getHistorySize() {
        return this.history.length;
    }
}
// ============================================================================
// 15. Strict MCP Config Flag
// ============================================================================
export class StrictMCPConfig {
    strict;
    configPath;
    allowedServers = new Set();
    constructor(strict, configPath) {
        this.strict = strict ?? false;
        this.configPath = configPath ?? null;
    }
    isStrict() {
        return this.strict;
    }
    setStrict(strict) {
        this.strict = strict;
        logger.info(`Strict MCP mode: ${strict ? 'enabled' : 'disabled'}`);
    }
    setConfigPath(path) {
        this.configPath = path;
    }
    addAllowedServer(serverName) {
        this.allowedServers.add(serverName);
    }
    isServerAllowed(serverName) {
        if (!this.strict)
            return true;
        return this.allowedServers.has(serverName);
    }
    getAllowedServers() {
        return [...this.allowedServers];
    }
    getConfigPath() {
        return this.configPath;
    }
}
export class PromptStash {
    stash = [];
    maxStash;
    constructor(maxStash) {
        this.maxStash = maxStash ?? 20;
    }
    push(content, cursorPosition) {
        const prompt = {
            id: `stash-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
            content,
            cursorPosition: cursorPosition ?? content.length,
            timestamp: Date.now(),
        };
        this.stash.push(prompt);
        // Enforce max stash size - remove oldest
        if (this.stash.length > this.maxStash) {
            this.stash = this.stash.slice(-this.maxStash);
        }
        logger.debug(`Prompt stashed: ${prompt.id}`);
        return prompt;
    }
    pop() {
        return this.stash.pop() ?? null;
    }
    peek() {
        return this.stash.length > 0 ? this.stash[this.stash.length - 1] : null;
    }
    getAll() {
        return [...this.stash];
    }
    clear() {
        this.stash = [];
    }
    getSize() {
        return this.stash.length;
    }
    isEmpty() {
        return this.stash.length === 0;
    }
    getMaxStash() {
        return this.maxStash;
    }
}
//# sourceMappingURL=cli-enhancements.js.map