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().
This commit is contained in:
ismeth
2026-02-28 00:23:33 +01:00
committed by YeonGyu-Kim
parent 8676b1cdb9
commit 684b746ee7
2 changed files with 28 additions and 2 deletions
+14 -1
View File
@@ -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<string, ToolDefinition
"simply omit it for the default behavior. Must be a valid directory path if provided."
),
},
<<<<<<< HEAD
execute: async (args, context) => {
||||||| 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<string, unknown>
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
+14 -1
View File
@@ -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<string, ToolDefinition
.optional()
.describe("Limit output to first N entries. 0 or omitted means no limit."),
},
<<<<<<< HEAD
execute: async (args, context) => {
||||||| 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<string, unknown>
const dir = typeof runtimeCtx.directory === "string" ? runtimeCtx.directory : ctx.directory
@@ -46,6 +53,12 @@ export function createGrepTools(ctx: PluginInput): Record<string, ToolDefinition
=======
const searchPath = args.path ? resolve(ctx.directory, args.path) : ctx.directory
>>>>>>> 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