UNPKG

hataraku

Version:

An autonomous coding agent for building AI-powered development tools. The name "Hataraku" (働く) means "to work" in Japanese.

73 lines 2.92 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.searchFiles = searchFiles; const child_process_1 = require("child_process"); const util = __importStar(require("util")); const execAsync = util.promisify(child_process_1.exec); /** * Searches for files matching a pattern using ripgrep * * @param cwd - The current working directory from which to execute the search * @param searchPath - The path to search within * @param pattern - The regex pattern to search for in files * @param filePattern - Optional glob pattern to filter which files to search * @returns A string containing the search results or 'No matches found' if no results * @throws Will throw an error if the ripgrep command fails for reasons other than no matches * @example * ```typescript * // Search for "function" in all TypeScript files in the src directory * const results = await searchFiles('/path/to/project', 'src', 'function', '*.ts'); * ``` */ async function searchFiles(cwd, searchPath, pattern, filePattern) { try { // Build ripgrep command let command = `rg --no-heading --line-number "${pattern}"`; if (filePattern) { command += ` -g "${filePattern}"`; } command += ` "${searchPath}"`; const { stdout } = await execAsync(command, { cwd }); return stdout || 'No matches found'; } catch (error) { if (error.code === 1 && !error.stdout) { return 'No matches found'; } throw error; } } //# sourceMappingURL=search.js.map