pull/14725/merge
defalut 2026-04-08 13:05:38 +08:00 committed by GitHub
commit c67a914025
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 18 additions and 3 deletions

View File

@ -12,6 +12,19 @@ import { assertExternalDirectory } from "./external-directory"
const MAX_LINE_LENGTH = 2000
function normalizeInclude(include?: string) {
if (!include) return undefined
const v = include.trim()
if (!v) return undefined
// Treat “match everything” globs as redundant. Passing them via --glob can
// act as an override/whitelist and may cause ignored paths to be searched.
const redundant = new Set(["*", "*.*", "**", "**/*", "./**", "./**/*"])
if (redundant.has(v)) return undefined
return v
}
export const GrepTool = Tool.define("grep", {
description: DESCRIPTION,
parameters: z.object({
@ -24,6 +37,8 @@ export const GrepTool = Tool.define("grep", {
throw new Error("pattern is required")
}
const include = normalizeInclude(params.include)
await ctx.ask({
permission: "grep",
patterns: [params.pattern],
@ -31,7 +46,7 @@ export const GrepTool = Tool.define("grep", {
metadata: {
pattern: params.pattern,
path: params.path,
include: params.include,
include: include,
},
})
@ -41,8 +56,8 @@ export const GrepTool = Tool.define("grep", {
const rgPath = await Ripgrep.filepath()
const args = ["-nH", "--hidden", "--no-messages", "--field-match-separator=|", "--regexp", params.pattern]
if (params.include) {
args.push("--glob", params.include)
if (include) {
args.push("--glob", include)
}
args.push(searchPath)