From 8676b1cdb984915bf98118df98a51839361fbc50 Mon Sep 17 00:00:00 2001 From: ismeth Date: Sat, 28 Feb 2026 00:23:33 +0100 Subject: [PATCH] fix(tools): resolve relative paths in glob/grep against project directory When models pass relative paths (e.g. 'apps/ios/CleanSlate') to glob/grep tools, they were passed directly to ripgrep which resolved them against process.cwd(). In OpenCode Desktop, process.cwd() is '/' causing all relative path lookups to fail with 'No such file or directory'. Fix: use path.resolve(ctx.directory, args.path) to resolve relative paths against the project directory instead of relying on process.cwd(). --- src/tools/glob/tools.ts | 8 ++++++++ src/tools/grep/tools.ts | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/src/tools/glob/tools.ts b/src/tools/glob/tools.ts index cdfa983b4..919193fcf 100644 --- a/src/tools/glob/tools.ts +++ b/src/tools/glob/tools.ts @@ -26,9 +26,17 @@ export function createGlobTools(ctx: PluginInput): Record { try { const cli = await resolveGrepCliWithAutoInstall() +<<<<<<< HEAD const runtimeCtx = context as Record const dir = typeof runtimeCtx.directory === "string" ? runtimeCtx.directory : ctx.directory const searchPath = args.path ? resolve(dir, args.path) : dir +||||||| parent of 804d517f (fix(tools): resolve relative paths in glob/grep against project directory) + const searchPath = args.path ?? ctx.directory + const paths = [searchPath] +======= + const searchPath = args.path ? resolve(ctx.directory, args.path) : ctx.directory + const paths = [searchPath] +>>>>>>> 804d517f (fix(tools): resolve relative paths in glob/grep against project directory) const result = await runRgFiles( { diff --git a/src/tools/grep/tools.ts b/src/tools/grep/tools.ts index eaf8a3972..7b4502bef 100644 --- a/src/tools/grep/tools.ts +++ b/src/tools/grep/tools.ts @@ -37,9 +37,15 @@ export function createGrepTools(ctx: PluginInput): Record { try { const globs = args.include ? [args.include] : undefined +<<<<<<< HEAD const runtimeCtx = context as Record const dir = typeof runtimeCtx.directory === "string" ? runtimeCtx.directory : ctx.directory const searchPath = args.path ? resolve(dir, args.path) : dir +||||||| parent of 804d517f (fix(tools): resolve relative paths in glob/grep against project directory) + const searchPath = args.path ?? ctx.directory +======= + const searchPath = args.path ? resolve(ctx.directory, args.path) : ctx.directory +>>>>>>> 804d517f (fix(tools): resolve relative paths in glob/grep against project directory) const paths = [searchPath] const outputMode = args.output_mode ?? "files_with_matches" const headLimit = args.head_limit ?? 0