summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDax Raad <[email protected]>2025-06-15 21:26:32 -0400
committerDax Raad <[email protected]>2025-06-15 21:26:32 -0400
commitfe05edaa79588844bd748c8c07177c5312349495 (patch)
treeb3354cbdb6fff79a5390998d3c310bd6d6e54d86
parent7d174767b040397e1b03476716f642ebfc4d2030 (diff)
downloadopencode-fe05edaa79588844bd748c8c07177c5312349495.tar.gz
opencode-fe05edaa79588844bd748c8c07177c5312349495.zip
enhance ripgrep files function with query filtering and limit support
🤖 Generated with [opencode](https://opencode.ai) Co-Authored-By: opencode <[email protected]>
-rw-r--r--packages/opencode/src/external/ripgrep.ts17
-rw-r--r--packages/opencode/src/server/server.ts3
-rw-r--r--packages/opencode/src/session/system.ts10
3 files changed, 20 insertions, 10 deletions
diff --git a/packages/opencode/src/external/ripgrep.ts b/packages/opencode/src/external/ripgrep.ts
index 0c77673e3..5d627dba5 100644
--- a/packages/opencode/src/external/ripgrep.ts
+++ b/packages/opencode/src/external/ripgrep.ts
@@ -6,6 +6,7 @@ import { z } from "zod"
import { NamedError } from "../util/error"
import { lazy } from "../util/lazy"
import { $ } from "bun"
+import { Fzf } from "./fzf"
export namespace Ripgrep {
const PLATFORM = {
@@ -113,11 +114,17 @@ export namespace Ripgrep {
return filepath
}
- export async function files(cwd: string) {
- const result =
- await $`${await filepath()} --files --hidden --glob '!.git/*'`
- .cwd(cwd)
- .text()
+ export async function files(input: {
+ cwd: string
+ query?: string
+ limit?: number
+ }) {
+ const commands = [`${await filepath()} --files --hidden --glob='!.git/*'`]
+ 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()
return result.split("\n").filter(Boolean)
}
}
diff --git a/packages/opencode/src/server/server.ts b/packages/opencode/src/server/server.ts
index eb50f7496..275a0e2ba 100644
--- a/packages/opencode/src/server/server.ts
+++ b/packages/opencode/src/server/server.ts
@@ -14,6 +14,7 @@ import { mapValues } from "remeda"
import { NamedError } from "../util/error"
import { Fzf } from "../external/fzf"
import { ModelsDev } from "../provider/models"
+import { Ripgrep } from "../external/ripgrep"
const ERRORS = {
400: {
@@ -457,7 +458,7 @@ export namespace Server {
async (c) => {
const body = c.req.valid("json")
const app = App.info()
- const result = await Fzf.search({
+ const result = await Ripgrep.files({
cwd: app.path.cwd,
query: body.query,
limit: 10,
diff --git a/packages/opencode/src/session/system.ts b/packages/opencode/src/session/system.ts
index 9b124e41f..de128134f 100644
--- a/packages/opencode/src/session/system.ts
+++ b/packages/opencode/src/session/system.ts
@@ -1,7 +1,5 @@
import { App } from "../app/app"
-import { Fzf } from "../external/fzf"
import { Ripgrep } from "../external/ripgrep"
-import { ListTool } from "../tool/ls"
import { Filesystem } from "../util/filesystem"
import PROMPT_ANTHROPIC from "./prompt/anthropic.txt"
@@ -28,7 +26,9 @@ export namespace SystemPrompt {
const app = App.info()
const tree = async () => {
- const files = await Ripgrep.files(app.path.cwd)
+ const files = await Ripgrep.files({
+ cwd: app.path.cwd,
+ })
type Node = {
children: Record<string, Node>
}
@@ -52,6 +52,7 @@ export namespace SystemPrompt {
}
function render(path: string[], node: Node): string {
+ // if (path.length === 3) return "\t".repeat(path.length) + "..."
const lines: string[] = []
const entries = Object.entries(node.children).sort(([a], [b]) =>
a.localeCompare(b),
@@ -68,7 +69,8 @@ export namespace SystemPrompt {
return lines.join("\n")
}
- return render([], root)
+ const result = render([], root)
+ return result
}
return [