"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.truncate = exports.printKv = exports.printTable = exports.printJson = void 0; /** Print as JSON (compact). Safe for agent parsing. */ function printJson(value) { process.stdout.write(JSON.stringify(value) + '\n'); } exports.printJson = printJson; /** Print a human-readable table. columns: [{key, header, width?}]; rows: object[]. */ function printTable(columns, rows) { const headers = columns.map((c) => c.header); const widths = columns.map((c) => Math.max(c.header.length, ...rows.map((r) => String(r[c.key] ?? '').length))); const sep = widths.map((w) => '-'.repeat(w)).join(' '); const fmtRow = (r) => columns.map((c, i) => String(r[c.key] ?? '').padEnd(widths[i])).join(' '); process.stdout.write(headers.map((h, i) => h.padEnd(widths[i])).join(' ') + '\n'); process.stdout.write(sep + '\n'); rows.forEach((r) => process.stdout.write(fmtRow(r) + '\n')); } exports.printTable = printTable; /** Print key: value pairs vertically. */ function printKv(pairs) { const width = Math.max(...pairs.map(([k]) => k.length)); pairs.forEach(([k, v]) => { const val = typeof v === 'object' && v !== null ? JSON.stringify(v) : String(v ?? ''); process.stdout.write(`${k.padEnd(width)} ${val}\n`); }); } exports.printKv = printKv; /** Truncate a long string to width, appending ellipsis. */ function truncate(s, width = 40) { const str = String(s ?? ''); return str.length > width ? str.slice(0, width - 1) + '…' : str; } exports.truncate = truncate;