shell tool tweaks (#194)

This commit is contained in:
Olcan 2025-04-28 08:17:52 -07:00 committed by GitHub
parent a9dc2772dd
commit a8f679ccb5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 7 deletions

View File

@ -1,8 +1,11 @@
This is a minimal shell tool that executes a given command as `bash -c <command>`.
This tool executes a given shell command as `bash -c <command>`.
Command can be any valid single-line Bash command.
Command can start background processes using `&`.
The following information is returned:
Command: Given command.
Command: Executed command.
Directory: Directory (relative to project root) where command was executed, or `(root)`.
Stdout: Output on stdout stream. Can be `(empty)` or partial on error.
Stderr: Output on stderr stream. Can be `(empty)` or partial on error.
Error: Error or `(none)` if no error occurred.

View File

@ -43,12 +43,14 @@ export class ShellTool extends BaseTool<ShellToolParams, ToolResult> {
getDescription(params: ShellToolParams): string {
let description = `${params.command}`;
if (params.description) {
// replace any line breaks with spaces, in case instructions are not followed
description += ` (${params.description.replace(/\n/g, ' ')})`;
}
// append optional [./directory]
if (params.directory) {
description += ` @ ${params.directory}`;
description += ` [./${params.directory}]`;
}
// append optional (description), replacing any line breaks with spaces
// tool description/schema should specify a single line w/o line breaks
if (params.description) {
description += ` (${params.description.replace(/\n/g, ' ')})`;
}
return description;
}
@ -193,6 +195,7 @@ export class ShellTool extends BaseTool<ShellToolParams, ToolResult> {
return {
llmContent: [
`Command: ${params.command}`,
`Directory: ${params.directory || '(root)'}`,
`Stdout: ${stdout || '(empty)'}`,
`Stderr: ${stderr || '(empty)'}`,
`Error: ${error ?? '(none)'}`,