From 527c21ea90e348f415570112c85cc77fdcb2a4bd Mon Sep 17 00:00:00 2001 From: ismeth Date: Mon, 2 Feb 2026 11:34:33 +0100 Subject: [PATCH] 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 "/" --- src/tools/glob/tools.ts | 6 ++++-- src/tools/grep/tools.ts | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/tools/glob/tools.ts b/src/tools/glob/tools.ts index e7608274d..763a3fd4b 100644 --- a/src/tools/glob/tools.ts +++ b/src/tools/glob/tools.ts @@ -20,10 +20,12 @@ export const glob: ToolDefinition = tool({ "simply omit it for the default behavior. Must be a valid directory path if provided." ), }, - execute: async (args) => { + execute: async (args, ctx) => { try { 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( { diff --git a/src/tools/grep/tools.ts b/src/tools/grep/tools.ts index b809cc809..7e8f5faa8 100644 --- a/src/tools/grep/tools.ts +++ b/src/tools/grep/tools.ts @@ -20,10 +20,12 @@ export const grep: ToolDefinition = tool({ .optional() .describe("The directory to search in. Defaults to the current working directory."), }, - execute: async (args) => { + execute: async (args, ctx) => { try { 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({ pattern: args.pattern,