From 7cec6f7c8b6a87dc6732b87d6f4094d0806fbc6a 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 | 7 +++++-- src/tools/grep/tools.ts | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/tools/glob/tools.ts b/src/tools/glob/tools.ts index 361d43cde..d808377b2 100644 --- a/src/tools/glob/tools.ts +++ b/src/tools/glob/tools.ts @@ -1,3 +1,4 @@ +import { resolve } from "node:path" import type { PluginInput } from "@opencode-ai/plugin" import { tool, type ToolDefinition } from "@opencode-ai/plugin/tool" import { runRgFiles } from "./cli" @@ -22,10 +23,12 @@ export function createGlobTools(ctx: PluginInput): Record { + execute: async (args, context) => { try { const cli = await resolveGrepCliWithAutoInstall() - const searchPath = args.path ?? ctx.directory + const runtimeCtx = context as Record + const dir = typeof runtimeCtx.directory === "string" ? runtimeCtx.directory : ctx.directory + const searchPath = args.path ? resolve(dir, args.path) : dir const paths = [searchPath] const result = await runRgFiles( diff --git a/src/tools/grep/tools.ts b/src/tools/grep/tools.ts index e4d0e0e42..b00c47540 100644 --- a/src/tools/grep/tools.ts +++ b/src/tools/grep/tools.ts @@ -1,3 +1,4 @@ +import { resolve } from "node:path" import type { PluginInput } from "@opencode-ai/plugin" import { tool, type ToolDefinition } from "@opencode-ai/plugin/tool" import { runRg, runRgCount } from "./cli" @@ -32,10 +33,12 @@ export function createGrepTools(ctx: PluginInput): Record { + execute: async (args, context) => { try { const globs = args.include ? [args.include] : undefined - const searchPath = args.path ?? ctx.directory + const runtimeCtx = context as Record + const dir = typeof runtimeCtx.directory === "string" ? runtimeCtx.directory : ctx.directory + const searchPath = args.path ? resolve(dir, args.path) : dir const paths = [searchPath] const outputMode = args.output_mode ?? "files_with_matches" const headLimit = args.head_limit ?? 0