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:
@@ -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<string, ToolDefinition
|
||||
"simply omit it for the default behavior. Must be a valid directory path if provided."
|
||||
),
|
||||
},
|
||||
execute: async (args) => {
|
||||
execute: async (args, context) => {
|
||||
try {
|
||||
const cli = await resolveGrepCliWithAutoInstall()
|
||||
const searchPath = args.path ?? ctx.directory
|
||||
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
|
||||
const paths = [searchPath]
|
||||
|
||||
const result = await runRgFiles(
|
||||
|
||||
@@ -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<string, ToolDefinition
|
||||
.optional()
|
||||
.describe("Limit output to first N entries. 0 or omitted means no limit."),
|
||||
},
|
||||
execute: async (args) => {
|
||||
execute: async (args, context) => {
|
||||
try {
|
||||
const globs = args.include ? [args.include] : undefined
|
||||
const searchPath = args.path ?? ctx.directory
|
||||
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
|
||||
const paths = [searchPath]
|
||||
const outputMode = args.output_mode ?? "files_with_matches"
|
||||
const headLimit = args.head_limit ?? 0
|
||||
|
||||
Reference in New Issue
Block a user