UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

98 lines (97 loc) • 2.91 kB
import { n as sliceUtf16Safe } from "./utf16-slice-CuDyEXgS.mjs"; import { a as redactSensitiveFieldValue, s as redactSensitiveText } from "./redact-Mj7pppxC.mjs"; import { s as raceWithTimeout } from "./src-BPmQBLJp.mjs"; import { t as attachErrorDiagnostic } from "./error-diagnostics-CD3FocGA.mjs"; import "./logging-core-DxpUImpb.mjs"; import "./text-utility-runtime-Ds8jsG0J.mjs"; import "./process-runtime-DcBPEA8Y.mjs"; import { r as createOwnedStdioProcess } from "./owned-stdio-D7AQWLYW.mjs"; import "./time-runtime-DoAwjF0T.mjs"; import "./error-runtime-BM740gJj.mjs"; //#region extensions/anthropic/cli-process.ts const STDERR_CAPTURE_CHARS = 8192; const STDERR_DRAIN_GRACE_MS = 200; /** Owns process-wide diagnostics and the credentials needed to redact warm turns. */ function createClaudeCliProcessOwner(e, t) { const assertCurrent = () => { const t = e(); if (!t) throw new Error("Claude CLI run is no longer active."); t.assertCurrent?.(); }; assertCurrent(); const n = t?.createData(); let r = {}; let i; let a = false; let o = false; let s = ""; let c = false; const observeStderr = (e) => { i = e; e.onExit(() => { a = true; }); e.onStderr((e) => { let t = e; if (o) return; if (c) { const e = t.indexOf("\n"); if (e < 0) return; t = t.slice(e + 1); c = false; } s += t; if (s.length > STDERR_CAPTURE_CHARS) { const e = sliceUtf16Safe(s, -8192); const t = e.indexOf("\n"); s = t < 0 ? "" : e.slice(t + 1); c = t < 0; } }); }; return { [Symbol.dispose]() { o = true; n?.fill(0); r = {}; s = ""; }, spawn: async (e) => { assertCurrent(); r = e.env; const n = await createOwnedStdioProcess({ argv: [e.command, ...e.args], argv0: e.argv0, cwd: e.cwd, env: e.env, exactEnv: true, abortSignal: e.signal, assertCurrent, secretInput: t, terminateOnHostLoss: true, stdoutConsumption: "awaited" }); observeStderr(n); return n; }, async withDiagnostics(t) { const c = e(); if (o || !c || c.abortSignal?.aborted) return t; if (i && a) await raceWithTimeout(i.wait().catch(() => void 0), STDERR_DRAIN_GRACE_MS, () => void 0); if (o || e() !== c || c.abortSignal?.aborted) return t; let l = s; const u = [r, c.env].flatMap((e) => Object.entries(e).flatMap(([e, t]) => t && redactSensitiveFieldValue(e, t, { mode: "tools" }) !== t ? [t] : [])); if (n) u.push(n.toString("utf8")); for (const e of u.filter(Boolean)) for (const t of [ e, encodeURIComponent(e), JSON.stringify(e).slice(1, -1) ]) l = l.replaceAll(t, "[REDACTED]"); l = sliceUtf16Safe(redactSensitiveText(l, { mode: "tools" }), -2e3).trim(); if (l && t instanceof Error) attachErrorDiagnostic(t, `stderr (process-wide; may include earlier turns): ${l}`); return t; } }; } //#endregion export { createClaudeCliProcessOwner as t };