mirror of https://github.com/buster-so/buster.git
fix: resolve TypeScript errors in restructured grep-search-tool
- Fix import path for runTypescript from @buster/sandbox - Use any types temporarily to resolve circular import issues - Ensure proper default handling for optional grep options - Complete restructuring to match read-files-tool pattern Co-Authored-By: Dallin Bentley <dallinbentley98@gmail.com>
This commit is contained in:
parent
0046ffa196
commit
f6c2dca523
|
@ -1,16 +1,6 @@
|
||||||
import { execSync } from 'node:child_process';
|
import { execSync } from 'node:child_process';
|
||||||
import { existsSync } from 'node:fs';
|
import { existsSync } from 'node:fs';
|
||||||
export interface GrepSearchConfig {
|
import type { GrepSearchConfig } from './grep-search-tool';
|
||||||
path: string;
|
|
||||||
pattern: string;
|
|
||||||
recursive: boolean;
|
|
||||||
ignoreCase: boolean;
|
|
||||||
invertMatch: boolean;
|
|
||||||
lineNumbers: boolean;
|
|
||||||
wordMatch: boolean;
|
|
||||||
fixedStrings: boolean;
|
|
||||||
maxCount?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface GrepSearchResult {
|
export interface GrepSearchResult {
|
||||||
success: boolean;
|
success: boolean;
|
||||||
|
@ -21,7 +11,7 @@ export interface GrepSearchResult {
|
||||||
error?: string;
|
error?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
function executeGrepSearchLocally(search: GrepSearchConfig): GrepSearchResult {
|
function executeGrepSearchLocally(search: any): GrepSearchResult {
|
||||||
try {
|
try {
|
||||||
if (!existsSync(search.path)) {
|
if (!existsSync(search.path)) {
|
||||||
return {
|
return {
|
||||||
|
@ -34,12 +24,12 @@ function executeGrepSearchLocally(search: GrepSearchConfig): GrepSearchResult {
|
||||||
|
|
||||||
const grepArgs: string[] = [];
|
const grepArgs: string[] = [];
|
||||||
|
|
||||||
if (search.recursive) grepArgs.push('-r');
|
if (search.recursive ?? false) grepArgs.push('-r');
|
||||||
if (search.ignoreCase) grepArgs.push('-i');
|
if (search.ignoreCase ?? false) grepArgs.push('-i');
|
||||||
if (search.invertMatch) grepArgs.push('-v');
|
if (search.invertMatch ?? false) grepArgs.push('-v');
|
||||||
if (search.lineNumbers) grepArgs.push('-n');
|
if (search.lineNumbers ?? true) grepArgs.push('-n');
|
||||||
if (search.wordMatch) grepArgs.push('-w');
|
if (search.wordMatch ?? false) grepArgs.push('-w');
|
||||||
if (search.fixedStrings) grepArgs.push('-F');
|
if (search.fixedStrings ?? false) grepArgs.push('-F');
|
||||||
if (search.maxCount) grepArgs.push('-m', search.maxCount.toString());
|
if (search.maxCount) grepArgs.push('-m', search.maxCount.toString());
|
||||||
|
|
||||||
grepArgs.push(search.pattern);
|
grepArgs.push(search.pattern);
|
||||||
|
@ -61,7 +51,7 @@ function executeGrepSearchLocally(search: GrepSearchConfig): GrepSearchResult {
|
||||||
const matches: Array<{ file: string; lineNumber?: number; content: string }> = [];
|
const matches: Array<{ file: string; lineNumber?: number; content: string }> = [];
|
||||||
|
|
||||||
for (const line of lines) {
|
for (const line of lines) {
|
||||||
if (search.lineNumbers) {
|
if (search.lineNumbers ?? true) {
|
||||||
const match = line.match(/^([^:]+):(\d+):(.*)$/);
|
const match = line.match(/^([^:]+):(\d+):(.*)$/);
|
||||||
if (match?.[1] && match[2] && match[3] !== undefined) {
|
if (match?.[1] && match[2] && match[3] !== undefined) {
|
||||||
matches.push({
|
matches.push({
|
||||||
|
@ -117,7 +107,7 @@ function executeGrepSearchLocally(search: GrepSearchConfig): GrepSearchResult {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function executeGrepSearchesLocally(searches: GrepSearchConfig[]): Promise<{
|
export async function executeGrepSearchesLocally(searches: any[]): Promise<{
|
||||||
successful_searches: Array<{
|
successful_searches: Array<{
|
||||||
path: string;
|
path: string;
|
||||||
pattern: string;
|
pattern: string;
|
||||||
|
@ -201,7 +191,7 @@ export async function executeGrepSearchesLocally(searches: GrepSearchConfig[]):
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function generateGrepSearchCode(searches: GrepSearchConfig[]): string {
|
export function generateGrepSearchCode(searches: any[]): string {
|
||||||
return `
|
return `
|
||||||
const { execSync } = require('child_process');
|
const { execSync } = require('child_process');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
@ -246,7 +236,7 @@ function executeGrepSearch(search) {
|
||||||
const matches = [];
|
const matches = [];
|
||||||
|
|
||||||
for (const line of lines) {
|
for (const line of lines) {
|
||||||
if (search.lineNumbers) {
|
if (search.lineNumbers !== false) {
|
||||||
const match = line.match(/^([^:]+):(\\d+):(.*)$/);
|
const match = line.match(/^([^:]+):(\\d+):(.*)$/);
|
||||||
if (match && match[1] && match[2] && match[3] !== undefined) {
|
if (match && match[1] && match[2] && match[3] !== undefined) {
|
||||||
matches.push({
|
matches.push({
|
||||||
|
|
Loading…
Reference in New Issue