nohandcoder
Version:
An AI agent for code editing, searching, and project analysis
51 lines (50 loc) • 1.8 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReadFileTool = void 0;
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const chalk_1 = __importDefault(require("chalk"));
class ReadFileTool {
constructor(workspaceRoot) {
this.workspaceRoot = workspaceRoot;
}
getDefinition() {
return {
type: "function",
function: {
name: "readFile",
description: "Read the contents of a file",
parameters: {
type: "object",
properties: {
filePath: {
type: "string",
description: "Path to the file to read (relative to current directory)",
},
},
required: ["filePath"],
additionalProperties: false,
},
strict: true,
},
};
}
async execute(args) {
console.log(chalk_1.default.blue("\nReading file...", args.filePath));
const fullPath = path_1.default.isAbsolute(args.filePath)
? args.filePath
: path_1.default.join(this.workspaceRoot, args.filePath);
const content = await fs_1.default.promises.readFile(fullPath, "utf-8");
const stats = await fs_1.default.promises.stat(fullPath);
return {
path: args.filePath,
content,
size: stats.size,
modified: stats.mtime,
};
}
}
exports.ReadFileTool = ReadFileTool;
;