Files
oh-my-opencode/src/tools/glob/tools.ts
T
YeonGyu-Kim 71ac09bb63 fix: use process.cwd() instead of ctx.directory for glob/grep tools
ToolContext type from @opencode-ai/plugin/tool does not include
a 'directory' property, causing typecheck failure after rebase from dev.

Changed to use process.cwd() which is the same pattern used in
session-manager/tools.ts.
2026-02-05 02:23:48 +09:00

44 lines
1.5 KiB
TypeScript

import { tool, type ToolDefinition } from "@opencode-ai/plugin/tool"
import { runRgFiles } from "./cli"
import { resolveGrepCliWithAutoInstall } from "./constants"
import { formatGlobResult } from "./utils"
export const glob: ToolDefinition = tool({
description:
"Fast file pattern matching tool with safety limits (60s timeout, 100 file limit). " +
"Supports glob patterns like \"**/*.js\" or \"src/**/*.ts\". " +
"Returns matching file paths sorted by modification time. " +
"Use this tool when you need to find files by name patterns.",
args: {
pattern: tool.schema.string().describe("The glob pattern to match files against"),
path: tool.schema
.string()
.optional()
.describe(
"The directory to search in. If not specified, the current working directory will be used. " +
"IMPORTANT: Omit this field to use the default directory. DO NOT enter \"undefined\" or \"null\" - " +
"simply omit it for the default behavior. Must be a valid directory path if provided."
),
},
execute: async (args) => {
try {
const cli = await resolveGrepCliWithAutoInstall()
// Use process.cwd() as the default search path when no path is provided
const searchPath = args.path ?? process.cwd()
const paths = [searchPath]
const result = await runRgFiles(
{
pattern: args.pattern,
paths,
},
cli
)
return formatGlobResult(result)
} catch (e) {
return `Error: ${e instanceof Error ? e.message : String(e)}`
}
},
})