


























@@ -43,6 +43,7 @@ export const CROSS_OS_AGENT_TURN_TIMEOUT_SECONDS = parsePositiveIntegerEnv(
4343"OPENCLAW_CROSS_OS_AGENT_TURN_TIMEOUT_SECONDS",
4444600,
4545);
46+export const CROSS_OS_COMMAND_CAPTURE_TAIL_BYTES = 16 * 1024 * 1024;
4647const CROSS_OS_AGENT_TURN_OPTIONAL = resolveCrossOsAgentTurnOptional();
47484849const providerConfig = {
@@ -3585,6 +3586,31 @@ function gitCommand() {
35853586return process.platform === "win32" ? "git.exe" : "git";
35863587}
358735883589+function resolveCommandCaptureLimit(options) {
3590+const value = options.maxOutputBytes;
3591+if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
3592+return CROSS_OS_COMMAND_CAPTURE_TAIL_BYTES;
3593+}
3594+return Math.max(1, Math.floor(value));
3595+}
3596+3597+function appendBoundedCommandOutput(current, chunk, maxBytes) {
3598+const chunkBuffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk));
3599+if (chunkBuffer.byteLength >= maxBytes) {
3600+return chunkBuffer.subarray(chunkBuffer.byteLength - maxBytes).toString("utf8");
3601+}
3602+3603+const currentBuffer = Buffer.from(current);
3604+const nextBytes = currentBuffer.byteLength + chunkBuffer.byteLength;
3605+if (nextBytes <= maxBytes) {
3606+return `${current}${chunkBuffer.toString("utf8")}`;
3607+}
3608+3609+const currentTailBytes = maxBytes - chunkBuffer.byteLength;
3610+const currentTail = currentBuffer.subarray(currentBuffer.byteLength - currentTailBytes);
3611+return Buffer.concat([currentTail, chunkBuffer], maxBytes).toString("utf8");
3612+}
3613+35883614export async function runCommand(command, args, options) {
35893615const invocation = resolveCommandSpawnInvocation(command, args, {
35903616comSpec: options.env?.ComSpec ?? options.env?.COMSPEC,
@@ -3613,6 +3639,7 @@ async function runCommandInvocation(invocation, options) {
36133639let killWaitTimer = null;
36143640let timer = null;
36153641let heartbeatTimer = null;
3642+const maxCapturedOutputBytes = resolveCommandCaptureLimit(options);
3616364336173644const clearTimers = () => {
36183645if (timer) {
@@ -3687,12 +3714,12 @@ async function runCommandInvocation(invocation, options) {
3687371436883715child.stdout?.on("data", (chunk) => {
36893716const text = chunk.toString();
3690-stdout += text;
3717+stdout = appendBoundedCommandOutput(stdout, chunk, maxCapturedOutputBytes);
36913718logStream.write(text);
36923719});
36933720child.stderr?.on("data", (chunk) => {
36943721const text = chunk.toString();
3695-stderr += text;
3722+stderr = appendBoundedCommandOutput(stderr, chunk, maxCapturedOutputBytes);
36963723logStream.write(text);
36973724});
36983725此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。