From 684b746ee74b7c6a25a2ead5d327bcc5da98f581 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 | 15 ++++++++++++++- src/tools/grep/tools.ts | 15 ++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/tools/glob/tools.ts b/src/tools/glob/tools.ts index 919193fcf..f70687c1a 100644 --- a/src/tools/glob/tools.ts +++ b/src/tools/glob/tools.ts @@ -1,6 +1,6 @@ import { resolve } from "node:path" import type { PluginInput } from "@opencode-ai/plugin" -import { tool, type ToolDefinition } from "@opencode-ai/plugin/tool" +import { tool, type ToolDefinition, type ToolContext } from "@opencode-ai/plugin/tool" import { runRgFiles } from "./cli" import { resolveGrepCliWithAutoInstall } from "./constants" import { formatGlobResult } from "./result-formatter" @@ -23,15 +23,28 @@ export function createGlobTools(ctx: PluginInput): Record { +||||||| parent of a9d2407d (fix(tools): resolve relative paths in glob/grep against project directory) + execute: async (args) => { +======= + execute: async (args, context: ToolContext) => { +>>>>>>> a9d2407d (fix(tools): resolve relative paths in glob/grep against project directory) try { const cli = await resolveGrepCliWithAutoInstall() +<<<<<<< HEAD <<<<<<< 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 +||||||| parent of a9d2407d (fix(tools): resolve relative paths in glob/grep against project directory) + const searchPath = args.path ?? ctx.directory +======= + const dir = context?.directory ?? ctx.directory + const searchPath = args.path ? resolve(dir, args.path) : dir +>>>>>>> a9d2407d (fix(tools): resolve relative paths in glob/grep against project directory) const paths = [searchPath] ======= const searchPath = args.path ? resolve(ctx.directory, args.path) : ctx.directory diff --git a/src/tools/grep/tools.ts b/src/tools/grep/tools.ts index 7b4502bef..d885dfb33 100644 --- a/src/tools/grep/tools.ts +++ b/src/tools/grep/tools.ts @@ -1,6 +1,6 @@ import { resolve } from "node:path" import type { PluginInput } from "@opencode-ai/plugin" -import { tool, type ToolDefinition } from "@opencode-ai/plugin/tool" +import { tool, type ToolDefinition, type ToolContext } from "@opencode-ai/plugin/tool" import { runRg, runRgCount } from "./cli" import { resolveGrepCliWithAutoInstall } from "./constants" import { formatGrepResult, formatCountResult } from "./result-formatter" @@ -34,9 +34,16 @@ export function createGrepTools(ctx: PluginInput): Record { +||||||| parent of a9d2407d (fix(tools): resolve relative paths in glob/grep against project directory) + execute: async (args) => { +======= + execute: async (args, context: ToolContext) => { +>>>>>>> a9d2407d (fix(tools): resolve relative paths in glob/grep against project directory) try { const globs = args.include ? [args.include] : undefined +<<<<<<< HEAD <<<<<<< HEAD const runtimeCtx = context as Record const dir = typeof runtimeCtx.directory === "string" ? runtimeCtx.directory : ctx.directory @@ -46,6 +53,12 @@ export function createGrepTools(ctx: PluginInput): Record>>>>>> 804d517f (fix(tools): resolve relative paths in glob/grep against project directory) +||||||| parent of a9d2407d (fix(tools): resolve relative paths in glob/grep against project directory) + const searchPath = args.path ?? ctx.directory +======= + const dir = context?.directory ?? ctx.directory + const searchPath = args.path ? resolve(dir, args.path) : dir +>>>>>>> a9d2407d (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