/**
 * Shared response envelope renderer.
 *
 * Converts a transport-neutral `AdapterResponse` into a single string
 * payload. Both the CLI adapter (stdout) and the MCP adapter (content
 * block text) call this function; no transport-specific branching
 * happens upstream.
 *
 * Rendering rules:
 *   - `primary` is emitted verbatim.
 *   - `bullets` are joined with "\n" and appended after a blank line if
 *     non-empty.
 *   - `jsonDetails` are emitted as a fenced ```json block, prefixed by
 *     the provided label. Suppressed when `format === 'compact'` or when
 *     `fencedJson` is false.
 *   - `trailer` (telemetry / nudges) is appended last when
 *     `includeTrailer !== false`. Compact responses may pass `false`.
 */
import { formatBullets } from './bullets.js';
import { formatJsonDetails } from './json-details.js';
export function renderEnvelope(response, opts = {}) {
    const fencedJson = opts.fencedJson !== false;
    const includeTrailer = opts.includeTrailer !== false;
    const chunks = [response.primary];
    if (response.bullets && response.bullets.length > 0) {
        const bulletBlock = formatBullets(response.bullets);
        if (bulletBlock)
            chunks.push(bulletBlock);
    }
    if (response.jsonDetails && response.format !== 'compact' && fencedJson) {
        chunks.push(formatJsonDetails(response.jsonDetails.label, response.jsonDetails.value));
    }
    if (response.trailer && includeTrailer) {
        chunks.push(response.trailer);
    }
    return chunks.join('\n\n').trim();
}
