refactor: убрать дубли, развести слои, разбить тесты
- Support/FileWalker: один обход каталога вместо двух копий - Support/Bytes: форматирование размера вместо трёх копий - Support/UrlGuard: SSRF-проверки вынесены из HttpRequestTool - Support/AtomicWriter: запись вынесена из FileSandbox - HttpRequest: normalizeUrl/resolveRedirect — одна реализация URL-логики - AiClient поверх HttpTransport::request: один транспорт, одна TLS-логика (было две копии cURL-настроек), подсказка про AI_CAINFO переехала в HttpTransport - Http переименован в HttpTransport: транспорт/значение/инструмент больше не называются одинаково - Agent: удалён мёртвый withDefaults — ядро больше не зависит от tools - tests: раннер + support + cases по темам (agent, files, http, shell, logging, tools, architecture) - архитектурные тесты: src не импортирует Tools, tools не создают AiClient и не вызывают cURL напрямую - 100 тестов
This commit is contained in:
1 parent
74bb23c159
commit
76b3be7115
28 files changed
+2022
-1749
No files matched your search
@@ -5,6 +5,8 @@ declare(strict_types=1);
|
||||
namespace AiSdk\Tools;
|
||||
|
||||
use AiSdk\Tool;
|
||||
use AiSdk\Tools\Support\Bytes;
|
||||
use AiSdk\Tools\Support\FileWalker;
|
||||
|
||||
/**
|
||||
* Поиск по содержимому файлов внутри песочницы (аналог grep).
|
||||
@@ -14,7 +16,6 @@ use AiSdk\Tool;
|
||||
*/
|
||||
final class SearchFilesTool implements Tool
|
||||
{
|
||||
private const IGNORED = ['.git', '.idea', '.vscode', 'vendor', 'node_modules', 'var'];
|
||||
private const MAX_FILE = 1048576;
|
||||
private const MAX_LINE = 200;
|
||||
|
||||
@@ -100,7 +101,7 @@ final class SearchFilesTool implements Tool
|
||||
$truncated = false;
|
||||
|
||||
try {
|
||||
$this->eachFile($start, function (string $file) use (&$results, $regex, $glob, $limit): void {
|
||||
FileWalker::walk($start, function (string $file) use (&$results, $regex, $glob, $limit): void {
|
||||
$relative = $this->sandbox->relative($file);
|
||||
|
||||
if (!fnmatch($glob, $relative) && !fnmatch($glob, basename($file))) {
|
||||
@@ -192,30 +193,4 @@ final class SearchFilesTool implements Tool
|
||||
/**
|
||||
* @param callable(string): void $onFile
|
||||
*/
|
||||
private function eachFile(string $directory, callable $onFile): void
|
||||
{
|
||||
$entries = @scandir($directory);
|
||||
|
||||
if ($entries === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($entries as $name) {
|
||||
if ($name === '.' || $name === '..' || in_array($name, self::IGNORED, true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$path = $directory . DIRECTORY_SEPARATOR . $name;
|
||||
|
||||
if (is_dir($path)) {
|
||||
$this->eachFile($path, $onFile);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_file($path)) {
|
||||
$onFile($path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user