/**
 * Core dbg:size Command
 *
 * Prints terminal sizing and environment information.
 * Works in both V3 and V4.
 *
 * UI-agnostic - no TUI library imports.
 */
/**
 * Get terminal size information
 *
 * Returns safe values (never crashes if unavailable)
 */
function getTerminalSize() {
    // Screen dimensions (if available from blessed or similar)
    // Note: In core, we don't have screen object, so these will be N/A
    // UI layer can pass screen object if needed
    const screenCols = 'N/A';
    const screenRows = 'N/A';
    // Process stdout dimensions
    const stdoutCols = process.stdout.columns ?? 'N/A';
    const stdoutRows = process.stdout.rows ?? 'N/A';
    // Platform
    const platform = process.platform;
    // Terminal program detection
    const termProgram = process.env.TERM_PROGRAM ?? 'N/A';
    const termSession = process.env.WT_SESSION ?? process.env.TERM_SESSION_ID ?? 'N/A';
    const term = process.env.TERM ?? 'N/A';
    const colorTerm = process.env.COLORTERM ?? 'N/A';
    // SSH detection
    const sshTty = process.env.SSH_TTY ?? 'N/A';
    const sshConnection = process.env.SSH_CONNECTION ?? 'N/A';
    // CI detection
    const ci = process.env.CI ?? 'N/A';
    return {
        screenCols,
        screenRows,
        stdoutCols,
        stdoutRows,
        platform,
        termProgram,
        termSession,
        term,
        colorTerm,
        sshTty,
        sshConnection,
        ci,
    };
}
/**
 * Handle dbg:size command
 */
export function handleSizeCommand(ctx, args) {
    const size = getTerminalSize();
    const events = [
        {
            id: `dbg-size-1-${Date.now()}`,
            ts: Date.now(),
            tag: 'DBG',
            level: 'INFO',
            msg: `=== TERMINAL SIZE INFO ===`,
        },
        {
            id: `dbg-size-2-${Date.now()}`,
            ts: Date.now(),
            tag: 'DBG',
            level: 'INFO',
            msg: `screen: cols=${size.screenCols} rows=${size.screenRows}`,
        },
        {
            id: `dbg-size-3-${Date.now()}`,
            ts: Date.now(),
            tag: 'DBG',
            level: 'INFO',
            msg: `stdout: cols=${size.stdoutCols} rows=${size.stdoutRows}`,
        },
        {
            id: `dbg-size-4-${Date.now()}`,
            ts: Date.now(),
            tag: 'DBG',
            level: 'INFO',
            msg: `platform: ${size.platform}`,
        },
        {
            id: `dbg-size-5-${Date.now()}`,
            ts: Date.now(),
            tag: 'DBG',
            level: 'INFO',
            msg: `term: TERM_PROGRAM=${size.termProgram} WT_SESSION=${size.termSession}`,
        },
        {
            id: `dbg-size-6-${Date.now()}`,
            ts: Date.now(),
            tag: 'DBG',
            level: 'INFO',
            msg: `term: TERM=${size.term} COLORTERM=${size.colorTerm}`,
        },
        {
            id: `dbg-size-7-${Date.now()}`,
            ts: Date.now(),
            tag: 'DBG',
            level: 'INFO',
            msg: `ssh: SSH_TTY=${size.sshTty}`,
        },
        {
            id: `dbg-size-8-${Date.now()}`,
            ts: Date.now(),
            tag: 'DBG',
            level: 'INFO',
            msg: `ssh: SSH_CONNECTION=${size.sshConnection}`,
        },
        {
            id: `dbg-size-9-${Date.now()}`,
            ts: Date.now(),
            tag: 'DBG',
            level: 'INFO',
            msg: `env: CI=${size.ci}`,
        },
        {
            id: `dbg-size-10-${Date.now()}`,
            ts: Date.now(),
            tag: 'DBG',
            level: 'INFO',
            msg: `=== END SIZE INFO ===`,
        },
    ];
    return { events };
}
/**
 * Enhanced version that accepts screen object (for UI layers that have it)
 */
export function handleSizeCommandWithScreen(ctx, args, screen) {
    const baseSize = getTerminalSize();
    // Override screen dimensions if provided
    const screenCols = screen?.cols ?? screen?.width ?? baseSize.screenCols;
    const screenRows = screen?.rows ?? screen?.height ?? baseSize.screenRows;
    const events = [
        {
            id: `dbg-size-1-${Date.now()}`,
            ts: Date.now(),
            tag: 'DBG',
            level: 'INFO',
            msg: `=== TERMINAL SIZE INFO ===`,
        },
        {
            id: `dbg-size-2-${Date.now()}`,
            ts: Date.now(),
            tag: 'DBG',
            level: 'INFO',
            msg: `screen: cols=${screenCols} rows=${screenRows}`,
        },
        {
            id: `dbg-size-3-${Date.now()}`,
            ts: Date.now(),
            tag: 'DBG',
            level: 'INFO',
            msg: `stdout: cols=${baseSize.stdoutCols} rows=${baseSize.stdoutRows}`,
        },
        {
            id: `dbg-size-4-${Date.now()}`,
            ts: Date.now(),
            tag: 'DBG',
            level: 'INFO',
            msg: `platform: ${baseSize.platform}`,
        },
        {
            id: `dbg-size-5-${Date.now()}`,
            ts: Date.now(),
            tag: 'DBG',
            level: 'INFO',
            msg: `term: TERM_PROGRAM=${baseSize.termProgram} WT_SESSION=${baseSize.termSession}`,
        },
        {
            id: `dbg-size-6-${Date.now()}`,
            ts: Date.now(),
            tag: 'DBG',
            level: 'INFO',
            msg: `term: TERM=${baseSize.term} COLORTERM=${baseSize.colorTerm}`,
        },
        {
            id: `dbg-size-7-${Date.now()}`,
            ts: Date.now(),
            tag: 'DBG',
            level: 'INFO',
            msg: `ssh: SSH_TTY=${baseSize.sshTty}`,
        },
        {
            id: `dbg-size-8-${Date.now()}`,
            ts: Date.now(),
            tag: 'DBG',
            level: 'INFO',
            msg: `ssh: SSH_CONNECTION=${baseSize.sshConnection}`,
        },
        {
            id: `dbg-size-9-${Date.now()}`,
            ts: Date.now(),
            tag: 'DBG',
            level: 'INFO',
            msg: `env: CI=${baseSize.ci}`,
        },
        {
            id: `dbg-size-10-${Date.now()}`,
            ts: Date.now(),
            tag: 'DBG',
            level: 'INFO',
            msg: `=== END SIZE INFO ===`,
        },
    ];
    return { events };
}
//# sourceMappingURL=size.js.map