core: extract external directory validation to shared utility to reduce code duplication across tools

This commit is contained in:
Dax Raad
2026-01-10 18:49:36 -05:00
parent 76386f5cfc
commit f94ee5ce90
10 changed files with 186 additions and 49 deletions

View File

@@ -4,6 +4,8 @@ import { Ripgrep } from "../file/ripgrep"
import DESCRIPTION from "./grep.txt"
import { Instance } from "../project/instance"
import path from "path"
import { assertExternalDirectory } from "./external-directory"
const MAX_LINE_LENGTH = 2000
@@ -30,7 +32,9 @@ export const GrepTool = Tool.define("grep", {
},
})
const searchPath = params.path || Instance.directory
let searchPath = params.path ?? Instance.directory
searchPath = path.isAbsolute(searchPath) ? searchPath : path.resolve(Instance.directory, searchPath)
await assertExternalDirectory(ctx, searchPath, { kind: "directory" })
const rgPath = await Ripgrep.filepath()
const args = ["-nH", "--hidden", "--follow", "--field-match-separator=|", "--regexp", params.pattern]