UNPKG

@n1k1t/unit-generator

Version:

Coverage based unit tests AI generator

64 lines 2.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const v3_1 = require("zod/v3"); const model_1 = require("./model"); const utils_1 = require("./utils"); const content_1 = require("../../content"); const file_1 = require("../../file"); exports.default = model_1.LlmToolCompiler .build(content_1.ArticleContent .build({ title: 'Read files contents', content: [ { p: `**Features:**` }, { ul: [ 'Parameter `path` should be relative to the project', 'Options `start` and `end` are helpful to cut file content (not acceptable for virtual files)', ], }, { p: `**Usage:**` }, { ul: [ 'Use the `grep` tool before this to catch a required context', 'Use this tool only when there are no any ways to get a context of files', ], }, ], }) .render()) .input(v3_1.z.object({ path: v3_1.z.string().describe('The path to the file to read'), start: v3_1.z.number().optional().describe('The line number to start reading from (1-indexed)'), end: v3_1.z.number().optional().describe('The line number to end reading at (inclusive)'), })) .output(v3_1.z.string().describe('File content')) .execute(({ project }) => async ({ path, start, end }) => { try { if (!(0, utils_1.checkPatternIsRestricted)(path)) { throw model_1.LlmToolExecutionError.build('read', `Path "${path}" is going to out of scope the project`); } const file = await file_1.File.build(path, { cwd: project.cwd, state: 'existent', strict: true, }); if (start === undefined && end === undefined) { return file.content; } const lines = file.content.split('\n'); const sliced = lines.slice(start ? start - 1 : 0, end ? end : lines.length); const content = sliced.join('\n'); if (content.split(/\s+/).length > 5000) { throw model_1.LlmToolExecutionError.build('read', [ 'The file content is too large (over 5000 tokens).', 'Please use a smaller range with "start" and "end" parameters, or use the "grep" tool to find the relevant context', ]); } return content; } catch (error) { throw model_1.LlmToolExecutionError.build('read', error); } }); //# sourceMappingURL=read.js.map