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

+16 -21
View File
@@ -98,36 +98,31 @@ final class SearchFilesTool implements Tool
}
$results = [];
$truncated = false;
try {
FileWalker::walk($start, function (string $file) use (&$results, $regex, $glob, $limit): void {
$relative = $this->sandbox->relative($file);
FileWalker::walk($start, function (string $file) use (&$results, $regex, $glob, $limit): bool {
$relative = $this->sandbox->relative($file);
if (!fnmatch($glob, $relative) && !fnmatch($glob, basename($file))) {
return;
}
foreach ($this->matchLines($file, $regex) as $line) {
$results[] = $relative . ':' . $line;
if (count($results) >= $limit) {
throw new \RuntimeException('__limit__');
}
}
});
} catch (\RuntimeException $e) {
if ($e->getMessage() !== '__limit__') {
return 'Ошибка поиска: ' . $e->getMessage();
if (!fnmatch($glob, $relative) && !fnmatch($glob, basename($file))) {
return true;
}
$truncated = true;
}
foreach ($this->matchLines($file, $regex) as $line) {
$results[] = $relative . ':' . $line;
if (count($results) >= $limit) {
return false; // лимит: останавливаем обход
}
}
return true;
});
if ($results === []) {
return 'Ничего не найдено по "' . $pattern . '".';
}
$truncated = count($results) >= $limit;
return 'Найдено ' . count($results) . ($truncated ? ' (обрезано по лимиту ' . $limit . ')' : '') . ":\n"
. implode("\n", $results);
}