Skip to content

Commit 1b44b9c

Browse files
committed
refactor(tool): simplify rg permission to single 'rg' permission (#107)
- Change rg tool to use single 'rg' permission instead of 'glob'/'grep' - Update TOOL display mappings in github.ts and run.ts - Update explore agent and ACP agent permission configs - Add legacy migration for existing glob/grep configs - Update Permission schema in config.ts - Update all related tests One tool = one permission. Simpler, more intuitive.
1 parent 9e6f688 commit 1b44b9c

13 files changed

Lines changed: 28 additions & 81 deletions

File tree

‎packages/opencode/src/acp/agent.ts‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,8 +1287,7 @@ export namespace ACP {
12871287
case "write":
12881288
return "edit"
12891289

1290-
case "grep":
1291-
case "glob":
1290+
case "rg":
12921291
case "context7_resolve_library_id":
12931292
case "context7_get_library_docs":
12941293
return "search"
@@ -1309,8 +1308,7 @@ export namespace ACP {
13091308
case "edit":
13101309
case "write":
13111310
return input["filePath"] ? [{ path: input["filePath"] }] : []
1312-
case "glob":
1313-
case "grep":
1311+
case "rg":
13141312
return input["path"] ? [{ path: input["path"] }] : []
13151313
case "bash":
13161314
return []

‎packages/opencode/src/agent/agent.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ export namespace Agent {
127127
defaults,
128128
PermissionNext.fromConfig({
129129
"*": "deny",
130-
grep: "allow",
131-
glob: "allow",
130+
rg: "allow",
132131
list: "allow",
133132
bash: "allow",
134133
webfetch: "allow",

‎packages/opencode/src/cli/cmd/agent.ts‎

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,7 @@ import type { Argv } from "yargs"
1313

1414
type AgentMode = "all" | "primary" | "subagent"
1515

16-
const AVAILABLE_TOOLS = [
17-
"bash",
18-
"read",
19-
"write",
20-
"edit",
21-
"list",
22-
"glob",
23-
"grep",
24-
"webfetch",
25-
"task",
26-
"todowrite",
27-
"todoread",
28-
]
16+
const AVAILABLE_TOOLS = ["bash", "read", "write", "edit", "list", "rg", "webfetch", "task", "todowrite", "todoread"]
2917

3018
const AgentCreateCommand = cmd({
3119
command: "create",

‎packages/opencode/src/cli/cmd/github.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -818,8 +818,7 @@ export const GithubRunCommand = cmd({
818818
todoread: ["Todo", UI.Style.TEXT_WARNING_BOLD],
819819
bash: ["Bash", UI.Style.TEXT_DANGER_BOLD],
820820
edit: ["Edit", UI.Style.TEXT_SUCCESS_BOLD],
821-
glob: ["Glob", UI.Style.TEXT_INFO_BOLD],
822-
grep: ["Grep", UI.Style.TEXT_INFO_BOLD],
821+
rg: ["rg", UI.Style.TEXT_INFO_BOLD],
823822
list: ["List", UI.Style.TEXT_INFO_BOLD],
824823
read: ["Read", UI.Style.TEXT_HIGHLIGHT_BOLD],
825824
write: ["Write", UI.Style.TEXT_SUCCESS_BOLD],

‎packages/opencode/src/cli/cmd/run.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ const TOOL: Record<string, [string, string]> = {
1717
todoread: ["Todo", UI.Style.TEXT_WARNING_BOLD],
1818
bash: ["Bash", UI.Style.TEXT_DANGER_BOLD],
1919
edit: ["Edit", UI.Style.TEXT_SUCCESS_BOLD],
20-
glob: ["Glob", UI.Style.TEXT_INFO_BOLD],
21-
grep: ["Grep", UI.Style.TEXT_INFO_BOLD],
20+
rg: ["rg", UI.Style.TEXT_INFO_BOLD],
2221
list: ["List", UI.Style.TEXT_INFO_BOLD],
2322
read: ["Read", UI.Style.TEXT_HIGHLIGHT_BOLD],
2423
write: ["Write", UI.Style.TEXT_SUCCESS_BOLD],

‎packages/opencode/src/cli/cmd/tui/routes/session/index.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1429,7 +1429,7 @@ function ToolPart(props: { last: boolean; part: ToolPart; message: AssistantMess
14291429
<Match when={props.part.tool === "bash"}>
14301430
<Bash {...toolprops} />
14311431
</Match>
1432-
<Match when={props.part.tool === "glob" || props.part.tool === "grep"}>
1432+
<Match when={props.part.tool === "rg"}>
14331433
<Glob {...toolprops} />
14341434
</Match>
14351435
<Match when={props.part.tool === "read"}>

‎packages/opencode/src/cli/cmd/tui/routes/session/permission.tsx‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,8 @@ export function PermissionPrompt(props: { request: PermissionRequest }) {
204204
<Match when={props.request.permission === "read"}>
205205
<TextBody icon="→" title={`Read ` + normalizePath(input().filePath as string)} />
206206
</Match>
207-
<Match when={props.request.permission === "glob"}>
208-
<TextBody icon="✱" title={`Glob "` + (input().pattern ?? "") + `"`} />
209-
</Match>
210-
<Match when={props.request.permission === "grep"}>
211-
<TextBody icon="✱" title={`Grep "` + (input().pattern ?? "") + `"`} />
207+
<Match when={props.request.permission === "rg"}>
208+
<TextBody icon="✱" title={`rg "` + (input().pattern ?? "") + `"`} />
212209
</Match>
213210
<Match when={props.request.permission === "list"}>
214211
<TextBody icon="→" title={`List ` + normalizePath(input().path as string)} />

‎packages/opencode/src/cli/lite/summary.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ export function summarizeInput(tool: string, input?: Record<string, unknown>): s
55
if (tool === "bash") return str("command").slice(0, 60)
66
if (tool === "read") return str("filePath").split("/").slice(-2).join("/")
77
if (tool === "write" || tool === "edit") return str("filePath").split("/").slice(-2).join("/")
8-
if (tool === "rg" || tool === "grep") {
8+
if (tool === "rg") {
99
const pattern = str("pattern").slice(0, 30)
1010
const include = str("include")
1111
return include ? `"${pattern}" in ${include}` : `"${pattern}"`
1212
}
13-
if (tool === "glob") return str("pattern").slice(0, 60)
1413
if (tool === "task") {
1514
const agent = str("subagent_type")
1615
const desc = str("description").slice(0, 40)

‎packages/opencode/src/config/config.ts‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,18 @@ export namespace Config {
176176
result.permission = mergeDeep(perms, result.permission ?? {})
177177
}
178178

179+
// Migrate legacy glob/grep permissions to rg
180+
if (result.permission) {
181+
if (result.permission.glob) {
182+
result.permission.rg = result.permission.rg || result.permission.glob
183+
delete result.permission.glob
184+
}
185+
if (result.permission.grep) {
186+
result.permission.rg = result.permission.rg || result.permission.grep
187+
delete result.permission.grep
188+
}
189+
}
190+
179191
if (!result.username) result.username = os.userInfo().username
180192

181193
// Handle migration from autoshare to share field
@@ -526,8 +538,7 @@ export namespace Config {
526538
__originalKeys: z.string().array().optional(),
527539
read: PermissionRule.optional(),
528540
edit: PermissionRule.optional(),
529-
glob: PermissionRule.optional(),
530-
grep: PermissionRule.optional(),
541+
rg: PermissionRule.optional(),
531542
list: PermissionRule.optional(),
532543
bash: PermissionRule.optional(),
533544
task: PermissionRule.optional(),

‎packages/opencode/src/tool/rg.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Parameters:
4040
}
4141

4242
await ctx.ask({
43-
permission: params.files_only ? "glob" : "grep",
43+
permission: "rg",
4444
patterns: params.pattern ? [params.pattern] : [],
4545
always: ["*"],
4646
metadata: {

0 commit comments

Comments
 (0)