/**
 * Formats a background-agent tool call as a single status line. Shared by the
 * durable-memory and skill-proposal footer status renderers. Argument values
 * for known content-bearing keys (file bodies, edit replacements) are
 * redacted — the footer should identify what the fork is doing without
 * echoing generated file content.
 */
import stripAnsi from 'strip-ansi';
const MAX_ARG_CHARS = 100;
const MAX_TOTAL_CHARS = 160;
const REDACTED_ARG_KEYS = new Set([
    'body',
    'content',
    'input',
    'newText',
    'new_string',
    'oldText',
    'old_string',
    'replacement',
    'text'
]);
/** Strip control characters and ellipsize a status string to fit `maxChars`. */
function truncate(value, maxChars) {
    const normalized = stripAnsi(value)
        .replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g, '')
        .replace(/\s+/g, ' ')
        .trim();
    if (normalized.length <= maxChars)
        return normalized;
    return `${normalized.slice(0, maxChars - 1).trimEnd()}…`;
}
/** Stringify a tool-argument value (preserving strings as-is) and truncate it for display. */
function formatArgValue(value) {
    if (typeof value === 'string')
        return truncate(value, MAX_ARG_CHARS);
    return truncate(JSON.stringify(value) ?? String(value), MAX_ARG_CHARS);
}
/** Render `key=value` for one tool argument, redacting known content-bearing keys. */
function formatArg(key, value) {
    // Status lines should identify the operation without echoing generated file bodies.
    if (REDACTED_ARG_KEYS.has(key))
        return `${key}=[redacted]`;
    return `${key}=${formatArgValue(value)}`;
}
/** Format an in-flight tool call as a single status line for the footer. */
export function formatToolCallStatus(prefix, toolCall) {
    if (!toolCall)
        return `${prefix}: scanning`;
    const args = toolCall.arguments &&
        typeof toolCall.arguments === 'object' &&
        !Array.isArray(toolCall.arguments)
        ? Object.entries(toolCall.arguments)
            .map(([key, value]) => formatArg(key, value))
            .join(' ')
        : formatArgValue(toolCall.arguments);
    const detail = args.length > 0 ? `${toolCall.name} ${args}` : toolCall.name;
    return truncate(`${prefix}: ${detail}`, MAX_TOTAL_CHARS);
}
//# sourceMappingURL=tool-call-status.js.map