UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

453 lines (452 loc) • 22.5 kB
import { a as asOptionalRecord } from "./record-coerce-CVPuDqcc.mjs"; import { r as truncateUtf16Safe } from "./utf16-slice-CuDyEXgS.mjs"; import { i as isSensitiveUrlQueryParamName } from "./redact-sensitive-url-D-E7DGoc.mjs"; import { A as VENDOR_TOKEN_REDACT_PATTERNS, N as replaceRedactPattern, c as redactText, k as AWS_SECRET_ACCESS_KEY_MATCHER, p as resolveRedactOptions, s as redactSensitiveText } from "./redact-Mj7pppxC.mjs"; import { t as isBlockedObjectKey } from "./prototype-keys-CLGi5xDj.mjs"; import { c as tokenizeConcreteConfigPath } from "./dot-path-BJ4tyWKJ.mjs"; import { i as stripAnsi, n as sanitizeForLog } from "./ansi-CZa2t0Hf.mjs"; import { n as getSecretRedactionRegistryRevision } from "./secret-redaction-registry-Cy0acctn.mjs"; import { t as REDACTED_SENTINEL } from "./redact-sentinel-Db2p5Put.mjs"; import { t as isSecretRefShape } from "./redact-snapshot.secret-ref-DsdaGkng.mjs"; import { t as UPDATE_CANDIDATE_STARTUP_FAILURES } from "./update-preflight-details-BixaM8Je.mjs"; import path from "node:path"; import { constants } from "node:os"; import { getSystemErrorMap } from "node:util"; import { valid } from "semver"; //#region src/infra/sqlite-snapshot-diagnostics.ts const SQLITE_SNAPSHOT_CHANGE_REASONS = [ "source-disappeared", "source-identity-changed", "journal-state-changed", "journal-mode-changed", "wal-copy-unstable", "wal-changed-during-copy", "main-changed-during-copy", "rollback-journal-changed-during-copy", "recovery-data-appeared", "retained-snapshot-changed" ]; const SQLITE_SNAPSHOT_STABILIZATION_DETAILS = new RegExp(`\\(reason=(?:${SQLITE_SNAPSHOT_CHANGE_REASONS.join("|")}), attempts=[1-9][0-9]{0,2}\\)`, "u"); //#endregion //#region src/logging/diagnostic-support-causes.ts /** Extract only closed causes from already sanitized diagnostic lines. */ function readPublicSupportCauses(e) { return (e.match(/\b(?:GLIBC_\d{1,3}(?:\.\d{1,3}){1,2} not found|[Cc]onnection (?:refused|closed|timed out)|[Pp]ermission denied|[Nn]o space left on device|MCP error -?\d{1,5}|HTTP [1-5]\d{2}|Invalid package dist content inventory|SQLite (?:snapshot (?:hash|size) mismatch|file generation (?:changed while reading|did not stabilize)|source did not stabilize|WAL commit (?:header is unavailable or changing|publication could not be verified))|Package rollback (?:launcher backup changed|verification (?:timed out|failed))|attempt state write refused|sentinel transaction (?:refused|unavailable)|pipe closed|managed update handoff (?:exited before (?:responding|signaling readiness)|did not (?:respond|signal readiness)))\b/gu) ?? []).map((e) => e.replace(/^permission denied$/u, "Permission denied")).concat(e.match(SQLITE_SNAPSHOT_STABILIZATION_DETAILS) ?? []).concat(e.match(/^Update database (?:backup|rollback|capture) volume: needs \d{1,8}(?:\.\d)? (?:MiB|GiB); available \d{1,8}(?:\.\d)? (?:MiB|GiB)$/gmu) ?? []); } //#endregion //#region src/logging/diagnostic-support-key-check.ts /** Repeated schemas share field checks only within one support capture. */ function createSupportKeyChecker(e) { const t = /* @__PURE__ */ new WeakMap(); return (n, r) => { const i = getSecretRedactionRegistryRevision(); let a = t.get(r); if (a?.revision !== i) { a = { revision: i, keys: /* @__PURE__ */ new Set() }; t.set(r, a); } if (a.keys.has(n)) return true; if (e(n) !== n) return false; if (a.keys.size < 1e3) a.keys.add(n); return true; }; } //#endregion //#region src/logging/diagnostic-support-redaction.ts const SECRET_SUPPORT_FIELD_RE = /(?:authorization|cookie|credential|key|password|passwd|secret|token)/iu; const PAYLOAD_SUPPORT_FIELD_RE = /(?:body|chat|content|detail|error|header|instruction|message|payload|prompt|result|text|tool|transcript)/iu; const IDENTIFIER_SUPPORT_FIELD_RE = /(?:account[-_]?id|chat[-_]?id|conversation[-_]?id|email|message[-_]?id|phone|thread[-_]?id|user[-_]?id|username)/iu; const PRIVATE_MAP_SUPPORT_FIELD_RE = /^(?:accounts|chats|conversations|dms|messages|threads|users)$/iu; const CONFIG_PRIVATE_FIELD_RE = /(?:allow[-_]?from|allow[-_]?to|deny[-_]?from|deny[-_]?to|blocked[-_]?from|blocked[-_]?users|owner[-_]?id|sender[-_]?id|recipient[-_]?id)/iu; const SENSITIVE_COMMAND_ARG_RE = /^--(?:aws[-_]?secret[-_]?access[-_]?key|awsSecretAccessKey|SecretAccessKey|api[-_]?key|hook[-_]?token|password|password-file|passwd|secret|token)(?:=.*)?$/iu; const BASIC_AUTH_RE = /\bBasic\s+[A-Za-z0-9+/]+={0,2}/giu; const COOKIE_HEADER_RE = /\b(Cookie|Set-Cookie)\s*:\s*[^\r\n]+/giu; const AWS_ACCESS_KEY_ID_RE = /\b(?:AKIA|ASIA)[A-Z0-9]{16}\b/gu; const vendorTokenPatterns = resolveRedactOptions({ patterns: VENDOR_TOKEN_REDACT_PATTERNS }).patterns.filter((e) => e !== AWS_SECRET_ACCESS_KEY_MATCHER); const JWT_RE = /\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\b/gu; const URL_USERINFO_RE = /\b([a-z][a-z0-9+.-]*:\/\/)([^/@\s:?#]+)(?::([^/@\s?#]+))?@/giu; const URL_PARAM_RE = /([?&])([^=&\s]+)=([^&#\s]+)/giu; const EMAIL_RE = /\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/giu; const MATRIX_USER_ID_RE = /@[A-Za-z0-9._=-]+:[A-Za-z0-9.-]+/gu; const MATRIX_ROOM_ID_RE = /![A-Za-z0-9._=-]+:[A-Za-z0-9.-]+/gu; const MATRIX_EVENT_ID_RE = /\$[A-Za-z0-9_-]{16,}/gu; const HANDLE_RE = /(^|[^\w:/])@(?!openclaw\/[a-z0-9])[A-Za-z0-9_]{5,}\b(?!\.)/gu; const LONG_DECIMAL_ID_RE = /\b\d{9,}\b/gu; const MAX_SUPPORT_STRING_LENGTH = 2e3; const MAX_SUPPORT_SNAPSHOT_DEPTH = 10; const MAX_SUPPORT_ARRAY_ITEMS = 1e3; const MAX_SUPPORT_OBJECT_ENTRIES = 1e3; const DEFAULT_TRUNCATION_SUFFIX = "...<truncated>"; const TRUNCATED_SUPPORT_FIELD = "<truncated>"; const isUnchangedSupportKey = createSupportKeyChecker(redactTextForSupport); function isPrivateSupportField(e) { return SECRET_SUPPORT_FIELD_RE.test(e) || PAYLOAD_SUPPORT_FIELD_RE.test(e) || IDENTIFIER_SUPPORT_FIELD_RE.test(e); } function sanitizeSecretRefForSupport(e) { const t = createSupportRecord(); if (typeof e.source === "string") t.source = e.source; if (typeof e.provider === "string") t.provider = e.provider; t.id = "<redacted>"; return t; } function sanitizeSupportKey(e, t, n) { if (!n && !e.startsWith("<identifier#") && isUnchangedSupportKey(e, t)) return e; const r = t.identifierKeys ??= /* @__PURE__ */ new Map(); let i = r.get(e); if (i === void 0) { i = `<identifier#${r.size + 1}>`; r.set(e, i); } return i; } function createSupportRecord() { return Object.create(null); } function countOwnObjectEntries(e) { let t = 0; for (const n in e) if (Object.hasOwn(e, n)) t += 1; return t; } function limitedSupportObjectEntries(e) { let t = 0; const n = []; for (const r in e) { if (!Object.hasOwn(e, r)) continue; t += 1; if (isBlockedObjectKey(r) || n.length >= MAX_SUPPORT_OBJECT_ENTRIES) continue; n.push({ key: r, value: e[r] }); } n.sort((e, t) => e.key.localeCompare(t.key)); return { count: t, entries: n }; } function addTruncationMetadata(e, t) { if (t > MAX_SUPPORT_OBJECT_ENTRIES) e[TRUNCATED_SUPPORT_FIELD] = { truncated: true, count: t, limit: MAX_SUPPORT_OBJECT_ENTRIES }; } function supportArrayResult(e, t) { if (t <= MAX_SUPPORT_ARRAY_ITEMS) return e; return { items: e, truncated: true, count: t, limit: MAX_SUPPORT_ARRAY_ITEMS }; } function isWindowsAbsolutePath(e) { return /^(?:[A-Za-z]:[\\/]|\\\\)/u.test(e); } let cachedPathRedactionPrefixes; function pathRedactionPrefixes(e) { const t = [ e.stateDir, e.env.HOME, e.env.USERPROFILE ]; if (t.some((e) => e && !path.isAbsolute(e) && !isWindowsAbsolutePath(e))) return buildPathRedactionPrefixes(e); const n = cachedPathRedactionPrefixes; if (n && t.every((e, t) => e === n.inputs[t])) return n.prefixes; const r = buildPathRedactionPrefixes(e); cachedPathRedactionPrefixes = { inputs: t, prefixes: r }; return r; } function buildPathRedactionPrefixes(e) { const t = /* @__PURE__ */ new Map(); for (const [n, r] of [ [e.stateDir, "$OPENCLAW_STATE_DIR"], [e.env.HOME, "~"], [e.env.USERPROFILE, "~"] ]) { if (!n) continue; const e = isWindowsAbsolutePath(n) ? path.win32.resolve(n) : path.resolve(n); const i = isWindowsAbsolutePath(e); for (const n of i ? [e, e.replaceAll("\\", "/")] : [e]) if (!t.has(n)) t.set(n, { prefix: n, label: r, caseInsensitive: i }); } return [...t.values()].toSorted((e, t) => t.prefix.length - e.prefix.length); } function pathCandidates(e) { if (!isWindowsAbsolutePath(e)) return [path.resolve(e)]; const t = path.win32.resolve(e); const n = [t, t.replaceAll("\\", "/")]; const r = WINDOWS_NAMESPACE_MARKER_RE.exec(e); if (r) { const t = e.slice(r[0].length); let i; if (/^UNC[\\/]/iu.test(t)) i = path.win32.resolve(`\\\\${t.slice(4)}`); else if (/^[A-Za-z]:[\\/]/u.test(t)) i = path.win32.resolve(t); if (i !== void 0) n.push(i, i.replaceAll("\\", "/")); } return n; } function hasPathPrefix(e, t) { return t.caseInsensitive ? e.toLowerCase().startsWith(t.prefix.toLowerCase()) : e.startsWith(t.prefix); } function matchPathPrefix(e, t) { if (e.length === t.prefix.length && hasPathPrefix(e, t)) return ""; if (!hasPathPrefix(e, t)) return; const n = e[t.prefix.length]; return n === "/" || n === "\\" ? e.slice(t.prefix.length) : void 0; } function isSupportAbsolutePath(e) { return path.isAbsolute(e) || isWindowsAbsolutePath(e); } function redactPathForSupport(e, t) { if (e == null || typeof e !== "string") return ""; if (e.startsWith("$")) return e; const n = pathCandidates(e); const r = pathRedactionPrefixes(t); for (const e of n) for (const t of r) { const n = matchPathPrefix(e, t); if (n !== void 0) return `${t.label}${n}`; } return redactSensitiveText(n[0] ?? e, { mode: "tools" }); } const WINDOWS_NAMESPACE_MARKER_RE = /^\\\\[?.][\\/]/u; const WINDOWS_NAMESPACE_MARKER_LENGTH = 4; function namespaceMarkerLengthBefore(e, t) { const n = t - WINDOWS_NAMESPACE_MARKER_LENGTH; if (n < 0) return 0; return WINDOWS_NAMESPACE_MARKER_RE.test(e.slice(n, t)) ? WINDOWS_NAMESPACE_MARKER_LENGTH : 0; } function replaceKnownPathPrefix(e, t) { const n = t.caseInsensitive ? t.prefix.toLowerCase() : t.prefix; const r = t.caseInsensitive ? e.toLowerCase() : e; let i = 0; let a = ""; while (i < e.length) { const o = r.indexOf(n, i); if (o === -1) { a += e.slice(i); break; } a += e.slice(i, o - namespaceMarkerLengthBefore(e, o)); a += t.label; i = o + t.prefix.length; } return a; } function redactKnownPathPrefixesForSupport(e, t) { let n = e; for (const e of pathRedactionPrefixes(t)) n = replaceKnownPathPrefix(n, e); return n; } function redactTextForSupport(e) { const t = e.replace(BASIC_AUTH_RE, "Basic <redacted>").replace(COOKIE_HEADER_RE, "$1: <redacted>").replace(AWS_ACCESS_KEY_ID_RE, "<redacted-aws-key>").replace(JWT_RE, "<redacted-jwt>"); const n = replaceRedactPattern(redactText(t, vendorTokenPatterns, { fullContext: true }), AWS_SECRET_ACCESS_KEY_MATCHER, () => "<redacted-aws-secret-key>"); return redactSensitiveText(n, { mode: "tools" }).replace(URL_USERINFO_RE, (e, t, n, r) => r ? `${t}<redacted>:<redacted>@` : `${t}<redacted>@`).replace(URL_PARAM_RE, (e, t, n) => isSensitiveUrlQueryParamName(n) ? `${t}${n}=<redacted>` : e).replace(MATRIX_USER_ID_RE, "<redacted-matrix-user>").replace(MATRIX_ROOM_ID_RE, "<redacted-matrix-room>").replace(MATRIX_EVENT_ID_RE, (e) => e === "$OPENCLAW_STATE_DIR" ? e : "<redacted-matrix-event>").replace(EMAIL_RE, "<redacted-email>").replace(HANDLE_RE, "$1<redacted-handle>").replace(LONG_DECIMAL_ID_RE, "<redacted-id>"); } function redactSupportString(e, t, n = {}) { const r = n.maxLength ?? MAX_SUPPORT_STRING_LENGTH; const i = n.truncationSuffix ?? DEFAULT_TRUNCATION_SUFFIX; const a = redactTextForSupport(e); const o = isSupportAbsolutePath(a) ? redactPathForSupport(a, t) : redactKnownPathPrefixesForSupport(a, t); if (o.length <= r) return o; return `${truncateUtf16Safe(o, r)}${i}`; } /** One diagnostic line; paths never expose private suffixes in public reports. */ function redactSupportDiagnosticLine(e, t, n = 200) { const r = redactSupportString(sanitizeForLog(stripAnsi(e).split(/[\r\n\u2028\u2029]/u).find((e) => e.trim()) ?? ""), t, { maxLength: Number.MAX_SAFE_INTEGER }).replace(/["'`]?(?:file:\/\/|\$OPENCLAW_STATE_DIR|(?:^|(?<=[\s=(:["'`]))(?:~[\\/]|[A-Za-z]:[\\/]|\/+|\\+)).*/gu, "[redacted-path]").replace(/\b(?:Command failed:|command (?:sh|cmd|powershell|bash)\b).*/giu, "[redacted-command]"); const i = /\bversion [`'"](GLIBC_\d{1,3}(?:\.\d{1,3}){1,2})['"] not found\b/u.exec(e)?.[1]; const a = i && !r.includes(`${i} not found`) ? `${i} not found; ${r.trim()}` : r.trim(); return truncateUtf16Safe(a, n); } const PUBLIC_ERROR_CODES = /* @__PURE__ */ new Set([ ...Array.from(getSystemErrorMap().values(), ([e]) => e), "ENOTFOUND", "EOTP", "ERESOLVE", "E401", "E403", "E404", "ETARGET", "EUSAGE", "EOVERRIDE", "EINVALIDTAGNAME", "EUNSUPPORTEDPROTOCOL", "EBADENGINE", "EINTEGRITY", "CERT_HAS_EXPIRED", "UNABLE_TO_VERIFY_LEAF_SIGNATURE", "SELF_SIGNED_CERT_IN_CHAIN", "DEPTH_ZERO_SELF_SIGNED_CERT", "ERR_MODULE_NOT_FOUND", "ERR_PACKAGE_PATH_NOT_EXPORTED", "ERR_SQLITE_ERROR", "SQLITE_BUSY", "SQLITE_LOCKED", "SQLITE_READONLY", "SQLITE_IOERR", "SQLITE_FULL" ]); /** Error-code syntax alone cannot distinguish private identifiers from known errors. */ function normalizeSupportDiagnosticErrorCode(e) { return e && PUBLIC_ERROR_CODES.has(e) ? e : void 0; } /** Custom SemVer labels can contain private project or host names. */ function redactPublicSupportVersion(e) { return e === "unknown" || e === "unspecified" || valid(e) && /^\d+\.\d+\.\d+(?:-(?:0|(?:alpha|beta|rc|dev)(?:\.\d{1,8})?))?$/u.test(e) ? e : "[redacted-version]"; } /** Validation paths may include operator-defined keys at any depth. */ function redactPublicSupportConfigKey(e, t) { if (t) { if (!e || e === "<root>") return "<root>"; try { const n = tokenizeConcreteConfigPath(e).tokens.map(String); if (n.length > 32) return "[redacted-key]"; return n.map((e, r) => t(n.slice(0, r), e)).join(".").slice(0, 128); } catch { return "[redacted-key]"; } } const n = /^(mcp(?:\.servers)?|models(?:\.providers)?|plugins(?:\.entries)?|skills(?:\.entries)?|auth(?:\.profiles)?|cron(?:\.jobs)?|agents(?:\.list)?|hooks(?:\.internal\.entries)?|engines(?:\.node)?|channels|commands|gateway|messages|session|stateDir|tools)(?:\.|$)/u.exec(e)?.[1]; return n ? e === n ? n : `${n}.*` : "[redacted-key]"; } const CONFIG_TYPES = "string|number|boolean|object|array|null|undefined|bigint|symbol|function|date|nan|int"; const CONFIG_TYPE_ISSUE = new RegExp(`^(?:Invalid input: )?expected (${CONFIG_TYPES}), (?:received|got) (${CONFIG_TYPES})$`, "u"); /** Only validator vocabulary and this known retired field leave private diagnostics. */ function publicConfigIssueMessage(e) { const t = CONFIG_TYPE_ISSUE.exec(e.message); if (t) return t[2] === "undefined" ? "missing required" : `expected ${t[1]}, got ${t[2]}`; if (e.message === "missing required") return e.message; if (/^(?:Unrecognized keys?: |unrecognized key )/u.test(e.message)) return `unrecognized key ${e.path === "skills.workshop" && /^(?:Unrecognized key: "approvalPolicy"|unrecognized key approvalPolicy)$/u.test(e.message) ? "approvalPolicy" : "<key>"}`; return "Invalid configuration field"; } /** Protocol-1 admission and startup diagnostics carry bounded field lines. */ function parsePublicConfigDiagnosticLines(e) { return e.split(/[\r\n\u2028\u2029]|; /u).flatMap((e) => { const t = /^(?:- )?(?:.+:\d+ — )?(.+?): (.+)$/u.exec(e); if (!t?.[1] || !t[2]) return []; const n = publicConfigIssueMessage({ path: t[1], message: t[2] }); return n !== "Invalid configuration field" || t[2] === n ? [{ path: t[1], message: n }] : []; }); } /** Public diagnostics expose recognized causes, never arbitrary prose or executable arguments. */ function redactPublicSupportDiagnosticLine(e, t) { const n = redactSupportDiagnosticLine(e, t); if (/^Client credential socket material is invalid\.(?: Failed migrating shared state database schema at \[redacted-path\])?$/u.test(n)) return "Client credential socket material is invalid."; const r = /^startup crash with signal (SIG[A-Z0-9]+)$/u.exec(n)?.[1]; if (!/[\r\n\u2028\u2029]/u.test(e) && (n === "readiness timeout" || UPDATE_CANDIDATE_STARTUP_FAILURES.some(([, e]) => e === n) || r && Object.hasOwn(constants.signals, r))) return n; const i = /^Gateway readiness was not verified; service status: (running|stopped|unknown)(?=[;.])/u.exec(n)?.[1]; if (i) return `Gateway readiness was not verified; service status: ${i}. Check openclaw gateway status --deep.`; if (/^Package recovery (?:anchor|control|journal|helper|rollback-journal) "[A-Za-z0-9_.-]{1,64}" unsafe: mode=[0-7]{4} nlink=\d{1,8} uid=\d{1,8}; expected owner-only mode(?: nlink=1)?\.(?: Run openclaw doctor --fix\.)?$/u.test(n)) return n; const a = /^Package rollback entry "([A-Za-z0-9_@.+/-]{1,90})": fields=((?:added|removed|dev:ino|mode|uid|gid|nlink|size|mtimeNs|ctimeNs|target|sha256)(?:,(?:dev:ino|mode|uid|gid|nlink|size|mtimeNs|ctimeNs|target|sha256))*)$/u.exec(n)?.[1]; if (a && !a.startsWith("/") && a.split("/").every((e) => e !== ".." && (!e.includes("@") || e === "@openclaw"))) return n; if (n === "Invalid configuration field" || n === "Configuration could not be read.") return n; if (n.startsWith("System-scope Gateway package update cannot write its install root ")) return "System-scope Gateway package update cannot write its install root."; if ([ "The npm global install layout cannot stage a candidate. Reinstall with npm into its default global layout, then retry the update.", "Cannot locate the installed updater; run `openclaw doctor` before retrying.", "Managed update handoff requires a user-scope systemd unit; perform a manual system-service update.", "managed update handoff requires a finite restart deadline", "systemd-run is required to launch a transient user scope", "managed update handoff process start identity is unavailable", "managed update handoff returned an invalid readiness response", "managed update handoff helper lease identity is unavailable", "managed update handoff control input closed", "managed update ownership transfer failed", "requester-revoked", "Doctor could not enter maintenance. An agent database is in use. Stop the Gateway and other OpenClaw processes or reboot, then rerun openclaw doctor --fix." ].includes(n)) return n; const o = /^(?:(?:Error|DoctorMaintenanceRefusalError): )?Doctor could not enter maintenance\.(?: Error: The update parent owns Gateway activation\.)?/u.exec(n); if (o) return o[0]; const s = /^Required: openclaw@(\S+) (.*); detected: Node (\S+) at /u.exec(n); if (s) { const [, e = "", t = "", n = ""] = s; const r = /^(?:Node [0-9.<>=|^~* +]+|a working Node runtime)$/u.test(t) ? t : "[redacted-requirement]"; return truncateUtf16Safe(`Target package: openclaw@${redactPublicSupportVersion(e)}; Required runtime: ${r}; Running Node: ${redactPublicSupportVersion(n)}`, 200); } const c = /^Target package: openclaw@(\S+); Minimum Node engine: (\S+); Running Node: (\S+)$/u.exec(n); if (c) { const [e, t, n] = c.slice(1).map(redactPublicSupportVersion); return truncateUtf16Safe(`Target package: openclaw@${e}; Minimum Node engine: ${t}; Running Node: ${n}`, 200); } if (/^Gateway readiness endpoint returned HTTP (?:[1-5]\d{2}|unavailable); expected HTTP 200\.$/u.test(n)) return n; const l = e.split(/[\r\n\u2028\u2029]/u).map((e) => redactSupportDiagnosticLine(e, t)).join("\n"); const u = (l.match(/\b[A-Z][A-Z0-9_]+\b/gu) ?? []).filter((e) => normalizeSupportDiagnosticErrorCode(e)); const d = readPublicSupportCauses(l); const f = parsePublicConfigDiagnosticLines(e).map((e) => `${redactPublicSupportConfigKey(e.path, t.redactConfigPathSegment)}: ${e.message}`); return truncateUtf16Safe([.../* @__PURE__ */ new Set([ ...u, ...d, ...f ])].join("; ") || "[redacted-diagnostic]", 200); } function sanitizeCommandArguments(e, t) { let n = false; return e.map((e) => { if (typeof e !== "string") return sanitizeSupportSnapshotValue(e, t); if (n) { n = false; return "<redacted>"; } if (SENSITIVE_COMMAND_ARG_RE.test(e)) { const t = e.includes("="); if (!t) n = true; return t ? e.replace(/[=].*/u, "=<redacted>") : e; } return redactSupportString(e, t); }); } /** Sanitizes general diagnostic snapshots while keeping bounded object/array structure. */ function sanitizeSupportSnapshotValue(e, t, n = "", r = 0) { return sanitizeSupportValue(e, t, n, r, false); } /** Sanitizes config-shaped values with stricter private field handling. */ function sanitizeSupportConfigValue(e, t, n = "", r = 0) { return sanitizeSupportValue(e, t, n, r, true); } function sanitizeSupportValue(e, t, n, r, i) { if (e == null || typeof e === "boolean") return e; const a = isPrivateSupportField(n) || i && CONFIG_PRIVATE_FIELD_RE.test(n); if (typeof e === "number") return a ? "<redacted>" : e; if (typeof e === "string") return a || i && e === "__OPENCLAW_REDACTED__" ? "<redacted>" : redactSupportString(e, t); if (r >= MAX_SUPPORT_SNAPSHOT_DEPTH) return "<truncated>"; if (Array.isArray(e)) { if (i && a) return { redacted: true, count: e.length }; const o = e.length; const s = e.slice(0, MAX_SUPPORT_ARRAY_ITEMS); return supportArrayResult(!i && n === "programArguments" ? sanitizeCommandArguments(s, t) : s.map((e) => sanitizeSupportValue(e, t, n, r + 1, i)), o); } const o = asOptionalRecord(e); if (!o) return "<unsupported>"; if (i && a) return isSecretRefShape(o) ? sanitizeSecretRefForSupport(o) : "<redacted>"; const s = PRIVATE_MAP_SUPPORT_FIELD_RE.test(n); if (!i && s) return { count: countOwnObjectEntries(o) }; const c = createSupportRecord(); const { count: l, entries: u } = limitedSupportObjectEntries(o); for (const { key: e, value: n } of u) { const a = sanitizeSupportKey(e, t, s); c[a] = !i && isPrivateSupportField(e) ? "<redacted>" : sanitizeSupportValue(n, t, e, r + 1, i); } addTruncationMetadata(c, l); return c; } //#endregion export { redactPathForSupport as a, redactPublicSupportVersion as c, redactTextForSupport as d, sanitizeSupportConfigValue as f, redactKnownPathPrefixesForSupport as i, redactSupportDiagnosticLine as l, parsePublicConfigDiagnosticLines as n, redactPublicSupportConfigKey as o, sanitizeSupportSnapshotValue as p, publicConfigIssueMessage as r, redactPublicSupportDiagnosticLine as s, normalizeSupportDiagnosticErrorCode as t, redactSupportString as u };