refactor: убрать мёртвый API и сентинель-исключение

- удалены неиспользуемые ToolRegistry::all(), FileSandbox::root(),
  ChatResult::\ (вместе с параметром конструктора)
- HttpRequestTool: allowPrivate больше не свойство, только параметр
- FileWalker возвращает bool: колбэк возвращает false, чтобы остановить
  обход; из search_files и find_files убраны throw/catch '__limit__'
- добавлены тесты лимита для search_files и find_files
- 102 теста
This commit is contained in:
rsgrinko committed 2026-11-12 23:29:51 +03:00
1 parent 27c0fc2477
commit 6734ca5289
9 files changed
+72 -66

No files matched your search

+11 -20
View File
@@ -76,35 +76,26 @@ final class FindFilesTool implements Tool
}
$found = [];
$truncated = false;
try {
FileWalker::walk($start, function (string $path) use (&$found, $pattern, $limit): void {
$relative = $this->sandbox->relative($path);
FileWalker::walk($start, function (string $path) use (&$found, $pattern, $limit): bool {
$relative = $this->sandbox->relative($path);
if (!fnmatch($pattern, $relative) && !fnmatch($pattern, basename($path))) {
return;
}
$size = @filesize($path);
$found[] = $relative . ' (' . Bytes::human($size === false ? 0 : $size) . ')';
if (count($found) >= $limit) {
throw new \RuntimeException('__limit__');
}
});
} catch (\RuntimeException $e) {
if ($e->getMessage() !== '__limit__') {
return 'Ошибка поиска: ' . $e->getMessage();
if (!fnmatch($pattern, $relative) && !fnmatch($pattern, basename($path))) {
return true;
}
$truncated = true;
}
$size = @filesize($path);
$found[] = $relative . ' (' . Bytes::human($size === false ? 0 : $size) . ')';
return count($found) < $limit;
});
if ($found === []) {
return 'Файлы не найдены по маске "' . $pattern . '".';
}
$truncated = count($found) >= $limit;
return 'Найдено ' . count($found) . ($truncated ? ' (обрезано по лимиту ' . $limit . ')' : '') . ":\n"
. implode("\n", $found);
}