summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDax Raad <[email protected]>2025-06-23 17:37:32 -0400
committerDax Raad <[email protected]>2025-06-23 17:37:32 -0400
commitf19c6b05f25b39eadb1b3e01633de1b6e4f4c9d6 (patch)
tree54c25a0293be9d2aae5207259c2117437480ea03
parentbc34f08333440c61f7c5dc1cd6e8221c41e80680 (diff)
downloadopencode-f19c6b05f25b39eadb1b3e01633de1b6e4f4c9d6.tar.gz
opencode-f19c6b05f25b39eadb1b3e01633de1b6e4f4c9d6.zip
glob tool should respect .gitignore
-rw-r--r--packages/opencode/src/external/ripgrep.ts7
-rw-r--r--packages/opencode/src/tool/glob.ts7
2 files changed, 10 insertions, 4 deletions
diff --git a/packages/opencode/src/external/ripgrep.ts b/packages/opencode/src/external/ripgrep.ts
index 4bc9519fb..1b4f40580 100644
--- a/packages/opencode/src/external/ripgrep.ts
+++ b/packages/opencode/src/external/ripgrep.ts
@@ -116,14 +116,17 @@ export namespace Ripgrep {
export async function files(input: {
cwd: string
query?: string
+ glob?: string
limit?: number
}) {
- const commands = [`${await filepath()} --files --hidden --glob='!.git/*'`]
+ const commands = [
+ `${await filepath()} --files --hidden --glob='!.git/*' ${input.glob ? `--glob='${input.glob}'` : ``}`,
+ ]
if (input.query)
commands.push(`${await Fzf.filepath()} --filter=${input.query}`)
if (input.limit) commands.push(`head -n ${input.limit}`)
const joined = commands.join(" | ")
- const result = await $`${{ raw: joined }}`.cwd(input.cwd).text()
+ const result = await $`${{ raw: joined }}`.cwd(input.cwd).nothrow().text()
return result.split("\n").filter(Boolean)
}
}
diff --git a/packages/opencode/src/tool/glob.ts b/packages/opencode/src/tool/glob.ts
index 07df3abaf..93912db78 100644
--- a/packages/opencode/src/tool/glob.ts
+++ b/packages/opencode/src/tool/glob.ts
@@ -3,6 +3,7 @@ import path from "path"
import { Tool } from "./tool"
import { App } from "../app/app"
import DESCRIPTION from "./glob.txt"
+import { Ripgrep } from "../external/ripgrep"
export const GlobTool = Tool.define({
id: "glob",
@@ -24,10 +25,12 @@ export const GlobTool = Tool.define({
: path.resolve(app.path.cwd, search)
const limit = 100
- const glob = new Bun.Glob(params.pattern)
const files = []
let truncated = false
- for await (const file of glob.scan({ cwd: search, dot: true })) {
+ for (const file of await Ripgrep.files({
+ cwd: search,
+ glob: params.pattern,
+ })) {
if (files.length >= limit) {
truncated = true
break