- 注册 `LsTool` 和 `BashTool` 工具,支持目录操作和命令执行 - 增强工具调用逻辑,添加日志记录以提升调试能力 - 增加 `ToolRegistry` 和 `RunLoop` 的增量累积与排序优化 - 完善单元测试覆盖新工具的执行与行为验证
60 lines
1.4 KiB
PHP
60 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Tool\Tools;
|
|
|
|
use App\Services\Tool\Tool;
|
|
|
|
class BashTool implements Tool
|
|
{
|
|
|
|
public function name(): string
|
|
{
|
|
return 'bash';
|
|
}
|
|
|
|
public function description(): string
|
|
{
|
|
return 'Execute bash commands';
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function parameters(): array
|
|
{
|
|
return [
|
|
'type' => 'object',
|
|
'properties' => [
|
|
'directory' => [
|
|
'type' => 'string',
|
|
'description' => 'The directory to list',
|
|
'default' => '.',
|
|
],
|
|
'file' => [
|
|
'type' => 'string',
|
|
'description' => 'The file to read',
|
|
],
|
|
'command' => [
|
|
'type' => 'string',
|
|
'description' => 'The command to execute',
|
|
],
|
|
'user_confirmation_message' => [
|
|
'type' => 'string',
|
|
'description' => ' A message describing the purpose of this command, shown to the user for approval before execution ',
|
|
]
|
|
],
|
|
'required' => [],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function execute(array $arguments): array|string
|
|
{
|
|
return [
|
|
'output' => shell_exec($arguments['command']),
|
|
];
|
|
}
|
|
}
|