export function redactForAgentTick(value: unknown, maxLength = 4000): string { let text = typeof value === "string" ? value : JSON.stringify(value, null, 2); text = text.replace(/(authorization:\s*bearer\s+)[^\s]+/gi, "$1[REDACTED]"); text = text.replace(/((?:token|api[-_]?key|password|passwd|secret)\s*[=:]\s*)[^\s'\"]+/gi, "$1[REDACTED]"); text = text.replace( /(-----BEGIN [^-]+ PRIVATE KEY-----)[\s\S]*?(-----END [^-]+ PRIVATE KEY-----)/g, "$1\n[REDACTED]\n$2", ); if (text.length > maxLength) return `${text.slice(0, maxLength)}\n… [truncated]`; return text; }