summaryrefslogtreecommitdiff
path: root/packages/core/src/tools/shell.ts
diff options
context:
space:
mode:
authorSijie Wang <[email protected]>2025-06-15 02:19:19 -0700
committerGitHub <[email protected]>2025-06-15 09:19:19 +0000
commit7352cb403c3ba0d70863f4daefefe0fddb56200e (patch)
treebe04d9e0ac23d0764065ff2e21b3f6f180207a34 /packages/core/src/tools/shell.ts
parent2b799cbbf0277fcd2b6c0a25b91123e6a9c2f49b (diff)
fix(core): Improve shell tool reliability and test portability (#1036)
Diffstat (limited to 'packages/core/src/tools/shell.ts')
-rw-r--r--packages/core/src/tools/shell.ts13
1 files changed, 4 insertions, 9 deletions
diff --git a/packages/core/src/tools/shell.ts b/packages/core/src/tools/shell.ts
index 4bae498b..62dd8429 100644
--- a/packages/core/src/tools/shell.ts
+++ b/packages/core/src/tools/shell.ts
@@ -170,17 +170,16 @@ export class ShellTool extends BaseTool<ShellToolParams, ToolResult> {
}
const isWindows = os.platform() === 'win32';
+ const tempFileName = `shell_pgrep_${crypto
+ .randomBytes(6)
+ .toString('hex')}.tmp`;
+ const tempFilePath = path.join(os.tmpdir(), tempFileName);
// pgrep is not available on Windows, so we can't get background PIDs
const command = isWindows
? params.command
: (() => {
// wrap command to append subprocess pids (via pgrep) to temporary file
- const tempFileName = `shell_pgrep_${crypto
- .randomBytes(6)
- .toString('hex')}.tmp`;
- const tempFilePath = path.join(os.tmpdir(), tempFileName);
-
let command = params.command.trim();
if (!command.endsWith('&')) command += ';';
return `{ ${command} }; __code=$?; pgrep -g 0 >${tempFilePath} 2>&1; exit $__code;`;
@@ -293,10 +292,6 @@ export class ShellTool extends BaseTool<ShellToolParams, ToolResult> {
// parse pids (pgrep output) from temporary file and remove it
const backgroundPIDs: number[] = [];
if (os.platform() !== 'win32') {
- const tempFileName = `shell_pgrep_${crypto
- .randomBytes(6)
- .toString('hex')}.tmp`;
- const tempFilePath = path.join(os.tmpdir(), tempFileName);
if (fs.existsSync(tempFilePath)) {
const pgrepLines = fs
.readFileSync(tempFilePath, 'utf8')