Fix shell tool description to be os-specific (#6335)
This commit is contained in:
parent
088f074839
commit
01b8a7565c
|
@ -391,6 +391,46 @@ describe('ShellTool', () => {
|
||||||
expect(() => shellTool.build({ command: '' })).toThrow();
|
expect(() => shellTool.build({ command: '' })).toThrow();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('getDescription', () => {
|
||||||
|
it('should return the windows description when on windows', () => {
|
||||||
|
vi.mocked(os.platform).mockReturnValue('win32');
|
||||||
|
const shellTool = new ShellTool(mockConfig);
|
||||||
|
expect(shellTool.description)
|
||||||
|
.toEqual(`This tool executes a given shell command as \`cmd.exe /c <command>\`. Command can start background processes using \`start /b\`.
|
||||||
|
|
||||||
|
The following information is returned:
|
||||||
|
|
||||||
|
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 and for any unwaited background processes.
|
||||||
|
Stderr: Output on stderr stream. Can be \`(empty)\` or partial on error and for any unwaited background processes.
|
||||||
|
Error: Error or \`(none)\` if no error was reported for the subprocess.
|
||||||
|
Exit Code: Exit code or \`(none)\` if terminated by signal.
|
||||||
|
Signal: Signal number or \`(none)\` if no signal was received.
|
||||||
|
Background PIDs: List of background processes started or \`(none)\`.
|
||||||
|
Process Group PGID: Process group started or \`(none)\``);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return the non-windows description when not on windows', () => {
|
||||||
|
vi.mocked(os.platform).mockReturnValue('linux');
|
||||||
|
const shellTool = new ShellTool(mockConfig);
|
||||||
|
expect(shellTool.description)
|
||||||
|
.toEqual(`This tool executes a given shell command as \`bash -c <command>\`. Command can start background processes using \`&\`. Command is executed as a subprocess that leads its own process group. Command process group can be terminated as \`kill -- -PGID\` or signaled as \`kill -s SIGNAL -- -PGID\`.
|
||||||
|
|
||||||
|
The following information is returned:
|
||||||
|
|
||||||
|
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 and for any unwaited background processes.
|
||||||
|
Stderr: Output on stderr stream. Can be \`(empty)\` or partial on error and for any unwaited background processes.
|
||||||
|
Error: Error or \`(none)\` if no error was reported for the subprocess.
|
||||||
|
Exit Code: Exit code or \`(none)\` if terminated by signal.
|
||||||
|
Signal: Signal number or \`(none)\` if no signal was received.
|
||||||
|
Background PIDs: List of background processes started or \`(none)\`.
|
||||||
|
Process Group PGID: Process group started or \`(none)\``);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('build', () => {
|
describe('build', () => {
|
||||||
|
|
|
@ -293,18 +293,8 @@ class ShellToolInvocation extends BaseToolInvocation<
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ShellTool extends BaseDeclarativeTool<
|
function getShellToolDescription(): string {
|
||||||
ShellToolParams,
|
const returnedInfo = `
|
||||||
ToolResult
|
|
||||||
> {
|
|
||||||
static Name: string = 'run_shell_command';
|
|
||||||
private allowlist: Set<string> = new Set();
|
|
||||||
|
|
||||||
constructor(private readonly config: Config) {
|
|
||||||
super(
|
|
||||||
ShellTool.Name,
|
|
||||||
'Shell',
|
|
||||||
`This tool executes a given shell command as \`bash -c <command>\`. Command can start background processes using \`&\`. Command is executed as a subprocess that leads its own process group. Command process group can be terminated as \`kill -- -PGID\` or signaled as \`kill -s SIGNAL -- -PGID\`.
|
|
||||||
|
|
||||||
The following information is returned:
|
The following information is returned:
|
||||||
|
|
||||||
|
@ -316,14 +306,42 @@ export class ShellTool extends BaseDeclarativeTool<
|
||||||
Exit Code: Exit code or \`(none)\` if terminated by signal.
|
Exit Code: Exit code or \`(none)\` if terminated by signal.
|
||||||
Signal: Signal number or \`(none)\` if no signal was received.
|
Signal: Signal number or \`(none)\` if no signal was received.
|
||||||
Background PIDs: List of background processes started or \`(none)\`.
|
Background PIDs: List of background processes started or \`(none)\`.
|
||||||
Process Group PGID: Process group started or \`(none)\``,
|
Process Group PGID: Process group started or \`(none)\``;
|
||||||
|
|
||||||
|
if (os.platform() === 'win32') {
|
||||||
|
return `This tool executes a given shell command as \`cmd.exe /c <command>\`. Command can start background processes using \`start /b\`.${returnedInfo}`;
|
||||||
|
} else {
|
||||||
|
return `This tool executes a given shell command as \`bash -c <command>\`. Command can start background processes using \`&\`. Command is executed as a subprocess that leads its own process group. Command process group can be terminated as \`kill -- -PGID\` or signaled as \`kill -s SIGNAL -- -PGID\`.${returnedInfo}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCommandDescription(): string {
|
||||||
|
if (os.platform() === 'win32') {
|
||||||
|
return 'Exact command to execute as `cmd.exe /c <command>`';
|
||||||
|
} else {
|
||||||
|
return 'Exact bash command to execute as `bash -c <command>`';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ShellTool extends BaseDeclarativeTool<
|
||||||
|
ShellToolParams,
|
||||||
|
ToolResult
|
||||||
|
> {
|
||||||
|
static Name: string = 'run_shell_command';
|
||||||
|
private allowlist: Set<string> = new Set();
|
||||||
|
|
||||||
|
constructor(private readonly config: Config) {
|
||||||
|
super(
|
||||||
|
ShellTool.Name,
|
||||||
|
'Shell',
|
||||||
|
getShellToolDescription(),
|
||||||
Kind.Execute,
|
Kind.Execute,
|
||||||
{
|
{
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties: {
|
properties: {
|
||||||
command: {
|
command: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
description: 'Exact bash command to execute as `bash -c <command>`',
|
description: getCommandDescription(),
|
||||||
},
|
},
|
||||||
description: {
|
description: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
|
|
Loading…
Reference in New Issue