Merge pull request #2202 from ualtinok/fix/glob-grep-relative-path

fix(tools): resolve relative paths in glob/grep against project directory
This commit is contained in:
YeonGyu-Kim 2026-02-28 13:17:53 +09:00 committed by GitHub
commit 29d606241b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 4 deletions

View File

@ -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(

View File

@ -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