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:
@@ -26,9 +26,17 @@ export function createGlobTools(ctx: PluginInput): Record<string, ToolDefinition
|
|||||||
execute: async (args, context) => {
|
execute: async (args, context) => {
|
||||||
try {
|
try {
|
||||||
const cli = await resolveGrepCliWithAutoInstall()
|
const cli = await resolveGrepCliWithAutoInstall()
|
||||||
|
<<<<<<< HEAD
|
||||||
const runtimeCtx = context as Record<string, unknown>
|
const runtimeCtx = context as Record<string, unknown>
|
||||||
const dir = typeof runtimeCtx.directory === "string" ? runtimeCtx.directory : ctx.directory
|
const dir = typeof runtimeCtx.directory === "string" ? runtimeCtx.directory : ctx.directory
|
||||||
const searchPath = args.path ? resolve(dir, args.path) : dir
|
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(
|
const result = await runRgFiles(
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -37,9 +37,15 @@ export function createGrepTools(ctx: PluginInput): Record<string, ToolDefinition
|
|||||||
execute: async (args, context) => {
|
execute: async (args, context) => {
|
||||||
try {
|
try {
|
||||||
const globs = args.include ? [args.include] : undefined
|
const globs = args.include ? [args.include] : undefined
|
||||||
|
<<<<<<< HEAD
|
||||||
const runtimeCtx = context as Record<string, unknown>
|
const runtimeCtx = context as Record<string, unknown>
|
||||||
const dir = typeof runtimeCtx.directory === "string" ? runtimeCtx.directory : ctx.directory
|
const dir = typeof runtimeCtx.directory === "string" ? runtimeCtx.directory : ctx.directory
|
||||||
const searchPath = args.path ? resolve(dir, args.path) : dir
|
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 paths = [searchPath]
|
||||||
const outputMode = args.output_mode ?? "files_with_matches"
|
const outputMode = args.output_mode ?? "files_with_matches"
|
||||||
const headLimit = args.head_limit ?? 0
|
const headLimit = args.head_limit ?? 0
|
||||||
|
|||||||
Reference in New Issue
Block a user