UNPKG

nohandcoder

Version:

An AI agent for code editing, searching, and project analysis

80 lines (79 loc) 2.9 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.AnalyzeProjectTool = void 0; const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); const glob_1 = require("glob"); const chalk_1 = __importDefault(require("chalk")); class AnalyzeProjectTool { constructor(workspaceRoot) { this.workspaceRoot = workspaceRoot; } async getIgnorePatterns() { const gitignorePath = path_1.default.join(this.workspaceRoot, ".gitignore"); try { const content = await fs_1.default.promises.readFile(gitignorePath, "utf-8"); return content .split("\n") .map((line) => line.trim()) .filter((line) => line && !line.startsWith("#")) .map((pattern) => `**/${pattern}/**`); } catch (error) { console.warn(chalk_1.default.yellow("Warning: .gitignore file not found or cannot be read. Using default ignore patterns.")); return ["**/node_modules/**", "**/.git/**", "**/dist/**", "**/.env*"]; } } getDefinition() { return { type: "function", function: { name: "analyzeProject", description: "Analyze the project structure", parameters: { type: "object", properties: {}, additionalProperties: false, }, strict: true, }, }; } async execute() { console.log(chalk_1.default.blue("\nAnalyzing project structure...")); const ignorePatterns = await this.getIgnorePatterns(); const files = await (0, glob_1.glob)("**/*", { cwd: this.workspaceRoot, ignore: ignorePatterns, dot: false, }); const structure = { files: [], directories: [], totalFiles: 0, totalSize: 0, }; for (const file of files) { console.log(chalk_1.default.green("\nAnalyzing file:", file)); const fullPath = path_1.default.join(this.workspaceRoot, file); const stats = await fs_1.default.promises.stat(fullPath); if (stats.isDirectory()) { structure.directories.push(file); } else { structure.files.push({ path: file, size: stats.size, modified: stats.mtime, }); structure.totalFiles++; structure.totalSize += stats.size; } } return structure; } } exports.AnalyzeProjectTool = AnalyzeProjectTool;