feat: truncate Bash output to 5k lines
This commit is contained in:
parent
95b99281ad
commit
51f3df5411
2 changed files with 52 additions and 7 deletions
|
|
@ -184,6 +184,29 @@ describe("runTerminalCommandTool", () => {
|
|||
const lines = result.trim().split("\n");
|
||||
expect(lines).toHaveLength(1000);
|
||||
});
|
||||
|
||||
it("should truncate output when it exceeds 5000 lines", async () => {
|
||||
// Generate a command that produces more than 5000 lines
|
||||
const result = await runTerminalCommandTool.run({
|
||||
command: "seq 1 6000",
|
||||
});
|
||||
|
||||
// Should contain the truncation message
|
||||
expect(result).toContain(
|
||||
"[Output truncated to first 5000 lines of 6001 total]",
|
||||
);
|
||||
|
||||
// Should contain first line
|
||||
expect(result).toContain("1\n");
|
||||
|
||||
// Should contain line 5000 but not line 6000
|
||||
expect(result).toContain("5000");
|
||||
expect(result).not.toContain("6000");
|
||||
|
||||
// Count lines in the result - should be 5000 content lines + 2 truncation message lines
|
||||
const lines = result.split("\n");
|
||||
expect(lines).toHaveLength(5002); // 5000 content lines + empty line + truncation message
|
||||
});
|
||||
});
|
||||
|
||||
describe("command types", () => {
|
||||
|
|
|
|||
|
|
@ -62,11 +62,21 @@ The command will be executed from the current working directory: ${process.cwd()
|
|||
if (isResolved) return;
|
||||
isResolved = true;
|
||||
child.kill();
|
||||
const output = stdout + (stderr ? `\nStderr: ${stderr}` : "");
|
||||
resolve(
|
||||
output +
|
||||
`\n\n[Command timed out after ${TIMEOUT_MS / 1000} seconds of no output]`,
|
||||
);
|
||||
let output = stdout + (stderr ? `\nStderr: ${stderr}` : "");
|
||||
output += `\n\n[Command timed out after ${TIMEOUT_MS / 1000} seconds of no output]`;
|
||||
|
||||
// Truncate output if it has too many lines
|
||||
const lines = output.split("\n");
|
||||
if (lines.length > 5000) {
|
||||
const truncatedOutput = lines.slice(0, 5000).join("\n");
|
||||
resolve(
|
||||
truncatedOutput +
|
||||
`\n\n[Output truncated to first 5000 lines of ${lines.length} total]`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
resolve(output);
|
||||
}, TIMEOUT_MS);
|
||||
};
|
||||
|
||||
|
|
@ -106,11 +116,23 @@ The command will be executed from the current working directory: ${process.cwd()
|
|||
}
|
||||
}
|
||||
|
||||
let output = stdout;
|
||||
if (stderr) {
|
||||
resolve(stdout + `\nStderr: ${stderr}`);
|
||||
output = stdout + `\nStderr: ${stderr}`;
|
||||
}
|
||||
|
||||
// Truncate output if it has too many lines
|
||||
const lines = output.split("\n");
|
||||
if (lines.length > 5000) {
|
||||
const truncatedOutput = lines.slice(0, 5000).join("\n");
|
||||
resolve(
|
||||
truncatedOutput +
|
||||
`\n\n[Output truncated to first 5000 lines of ${lines.length} total]`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
resolve(stdout);
|
||||
|
||||
resolve(output);
|
||||
});
|
||||
|
||||
child.on("error", (error) => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue