UNPKG

@n1k1t/unit-generator

Version:

Coverage based unit tests AI generator

69 lines 2.89 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const v3_1 = require("zod/v3"); const lodash_1 = __importDefault(require("lodash")); const model_1 = require("./model"); const utils_1 = require("./utils"); const content_1 = require("../../content"); const rg_1 = require("../../rg"); exports.default = model_1.LlmToolCompiler .build(content_1.ArticleContent .build({ title: 'Fast content search tool that works with any codebase size', content: [ { p: `**Features:**` }, { ul: [ 'Searches file contents using regular expressions', 'Supports full regex syntax (eg. "log.*Error", "function\\s+\\w+", etc.)', 'Filter files by pattern with the include parameter (eg. "*.js", "*.{ts,tsx}")', 'Returns file paths and line numbers with at least one match sorted by modification time', ], }, { p: `**Usage:**` }, { ul: [ 'Use this tool when you need to find files containing specific patterns', ], }, ], }) .render()) .input(v3_1.z.object({ pattern: v3_1.z.string().describe('The regex pattern to search for in file contents'), path: v3_1.z.string().optional().describe('The directory to search in. Defaults to the current working directory.'), include: v3_1.z.string().optional().describe('File pattern to include in the search (e.g. "*.js", "*.{ts,tsx}")'), })) .output(v3_1.z.string().describe('Search results')) .execute(({ project }) => async ({ pattern, path: location, include }) => { try { if (location) { if (!(0, utils_1.checkPatternIsRestricted)(location)) { throw model_1.LlmToolExecutionError.build('grep', 'Pattern or path is going to out of scope the project'); } if (location.startsWith('__vfs__/')) { throw model_1.LlmToolExecutionError.build('grep', 'Cannot grep virtual file. Only `read` tool is allowed to work with this file'); } } const rg = rg_1.Rg.build(); const results = await rg.exec(pattern, { path: location, limit: 50, include: include ? [include] : undefined, exclude: project.sources.ignore, }); if (results.length === 0) { return 'No matches found.'; } return results .map((match) => `${match.path.text}:${match.line_number}: ${lodash_1.default.truncate(match.lines.text.trim(), { length: 100 })}`) .join('\n'); } catch (error) { throw model_1.LlmToolExecutionError.build('grep', error); } }); //# sourceMappingURL=grep.js.map