fix(tools): for overridden tools (glob, grep) path should use ctx.directory. OpenCode Desktop might not send path as a param and cwd might resolve to "/"

This commit is contained in:
ismeth 2026-02-02 11:34:33 +01:00
parent d165a6821d
commit 527c21ea90
2 changed files with 8 additions and 4 deletions

View File

@ -20,10 +20,12 @@ export const glob: ToolDefinition = tool({
"simply omit it for the default behavior. Must be a valid directory path if provided." "simply omit it for the default behavior. Must be a valid directory path if provided."
), ),
}, },
execute: async (args) => { execute: async (args, ctx) => {
try { try {
const cli = await resolveGrepCliWithAutoInstall() const cli = await resolveGrepCliWithAutoInstall()
const paths = args.path ? [args.path] : undefined // Use ctx.directory as the default search path when no path is provided
const searchPath = args.path ?? ctx.directory
const paths = [searchPath]
const result = await runRgFiles( const result = await runRgFiles(
{ {

View File

@ -20,10 +20,12 @@ export const grep: ToolDefinition = tool({
.optional() .optional()
.describe("The directory to search in. Defaults to the current working directory."), .describe("The directory to search in. Defaults to the current working directory."),
}, },
execute: async (args) => { execute: async (args, ctx) => {
try { try {
const globs = args.include ? [args.include] : undefined const globs = args.include ? [args.include] : undefined
const paths = args.path ? [args.path] : undefined // Use ctx.directory as the default search path when no path is provided
const searchPath = args.path ?? ctx.directory
const paths = [searchPath]
const result = await runRg({ const result = await runRg({
pattern: args.pattern, pattern: args.pattern,