





















@@ -28,6 +28,10 @@ const INSTALL_TIMEOUT_MS = readPositiveInt(
2828);
2929const RPC_TIMEOUT_MS = readPositiveInt(process.env.OPENCLAW_KITCHEN_SINK_RPC_CALL_MS, 60000);
3030const MAX_RSS_MIB = readPositiveInt(process.env.OPENCLAW_KITCHEN_SINK_MAX_RSS_MIB, 2048);
31+const OUTPUT_CAPTURE_CHARS = readPositiveInt(
32+process.env.OPENCLAW_KITCHEN_SINK_OUTPUT_CAPTURE_CHARS,
33+1024 * 1024,
34+);
3135const DEFAULT_PORT = 19000 + Math.floor(Math.random() * 1000);
32363337let callGatewayModulePromise;
@@ -109,14 +113,30 @@ function readJson(file) {
109113return JSON.parse(fs.readFileSync(file, "utf8"));
110114}
111115116+export function appendBoundedOutput(buffer, chunk, maxChars = OUTPUT_CAPTURE_CHARS) {
117+const text = String(chunk);
118+const combined = `${buffer.text}${text}`;
119+const overflowChars = Math.max(0, combined.length - maxChars);
120+return {
121+text: overflowChars > 0 ? combined.slice(overflowChars) : combined,
122+truncatedChars: buffer.truncatedChars + overflowChars,
123+};
124+}
125+126+function formatCapturedOutput(label, buffer) {
127+return buffer.truncatedChars > 0
128+ ? `[${label} truncated ${buffer.truncatedChars} chars]\n${buffer.text}`
129+ : buffer.text;
130+}
131+112132function runCommand(command, args, options = {}) {
113133return new Promise((resolve, reject) => {
114134const child = childProcess.spawn(command, args, {
115135stdio: ["ignore", "pipe", "pipe"],
116136 ...options,
117137});
118-let stdout = "";
119-let stderr = "";
138+let stdout = { text: "", truncatedChars: 0 };
139+let stderr = { text: "", truncatedChars: 0 };
120140const timeoutMs = options.timeoutMs ?? COMMAND_TIMEOUT_MS;
121141let timedOut = false;
122142const timer = setTimeout(() => {
@@ -125,10 +145,10 @@ function runCommand(command, args, options = {}) {
125145setTimeout(() => child.kill("SIGKILL"), 2000).unref();
126146}, timeoutMs);
127147child.stdout?.on("data", (chunk) => {
128-stdout += String(chunk);
148+stdout = appendBoundedOutput(stdout, chunk);
129149});
130150child.stderr?.on("data", (chunk) => {
131-stderr += String(chunk);
151+stderr = appendBoundedOutput(stderr, chunk);
132152});
133153child.on("error", (error) => {
134154clearTimeout(timer);
@@ -137,10 +157,21 @@ function runCommand(command, args, options = {}) {
137157child.on("close", (status, signal) => {
138158clearTimeout(timer);
139159if (status === 0) {
140-resolve({ stdout, stderr });
160+resolve({
161+stdout: stdout.text,
162+stderr: stderr.text,
163+stdoutTruncatedChars: stdout.truncatedChars,
164+stderrTruncatedChars: stderr.truncatedChars,
165+});
141166return;
142167}
143-const detail = [stdout, stderr].filter(Boolean).join("\n").trim();
168+const detail = [
169+formatCapturedOutput("stdout", stdout),
170+formatCapturedOutput("stderr", stderr),
171+]
172+.filter(Boolean)
173+.join("\n")
174+.trim();
144175const failure = timedOut
145176 ? `timed out after ${timeoutMs}ms`
146177 : `failed with ${signal || status}`;
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。