Skip to content

Commit 40ac46d

Browse files
Apply PR #12633: feat(tui): add auto-accept mode for permission requests
2 parents 93dd494 + 5792a80 commit 40ac46d

File tree

7 files changed

+40
-5
lines changed

7 files changed

+40
-5
lines changed

packages/opencode/src/agent/agent.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export const layer = Layer.effect(
9494
question: "deny",
9595
plan_enter: "deny",
9696
plan_exit: "deny",
97+
edit: "ask",
9798
// mirrors github.com/github/gitignore Node.gitignore pattern for .env files
9899
read: {
99100
"*": "allow",

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,11 @@ export const RunCommand = cmd({
367367
action: "deny",
368368
pattern: "*",
369369
},
370+
{
371+
permission: "edit",
372+
action: "allow",
373+
pattern: "*",
374+
},
370375
]
371376

372377
function title() {

packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ export function Prompt(props: PromptProps) {
112112
const [auto, setAuto] = createSignal<AutocompleteRef>()
113113
const currentProviderLabel = createMemo(() => local.model.parsed().provider)
114114
const hasRightContent = createMemo(() => Boolean(props.right))
115+
const [autoaccept, setAutoaccept] = kv.signal<"none" | "edit">("permission_auto_accept", "edit")
115116

116117
function promptModelWarning() {
117118
toast.show({
@@ -228,6 +229,17 @@ export function Prompt(props: PromptProps) {
228229

229230
command.register(() => {
230231
return [
232+
{
233+
title: autoaccept() === "none" ? "Enable autoedit" : "Disable autoedit",
234+
value: "permission.auto_accept.toggle",
235+
search: "toggle permissions",
236+
keybind: "permission_auto_accept_toggle",
237+
category: "Agent",
238+
onSelect: (dialog) => {
239+
setAutoaccept(() => (autoaccept() === "none" ? "edit" : "none"))
240+
dialog.clear()
241+
},
242+
},
231243
{
232244
title: "Clear prompt",
233245
value: "prompt.clear",
@@ -1226,6 +1238,11 @@ export function Prompt(props: PromptProps) {
12261238
{props.right}
12271239
</box>
12281240
</Show>
1241+
<Show when={autoaccept() === "edit"}>
1242+
<text>
1243+
<span style={{ fg: theme.warning }}>autoedit</span>
1244+
</text>
1245+
</Show>
12291246
</box>
12301247
</box>
12311248
</box>

packages/opencode/src/cli/cmd/tui/context/sync.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { createSimpleContext } from "./helper"
2727
import type { Snapshot } from "@/snapshot"
2828
import { useExit } from "./exit"
2929
import { useArgs } from "./args"
30+
import { useKV } from "./kv"
3031
import { batch, onMount } from "solid-js"
3132
import { Log } from "@/util"
3233
import { emptyConsoleState, type ConsoleState } from "@/config/console-state"
@@ -107,6 +108,8 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
107108
const event = useEvent()
108109
const project = useProject()
109110
const sdk = useSDK()
111+
const kv = useKV()
112+
const [autoaccept] = kv.signal<"none" | "edit">("permission_auto_accept", "edit")
110113

111114
const fullSyncedSessions = new Set<string>()
112115
let syncedWorkspace = project.workspace.current()
@@ -133,6 +136,13 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
133136

134137
case "permission.asked": {
135138
const request = event.properties
139+
if (autoaccept() === "edit" && request.permission === "edit") {
140+
void sdk.client.permission.reply({
141+
reply: "once",
142+
requestID: request.id,
143+
})
144+
break
145+
}
136146
const requests = store.permission[request.sessionID]
137147
if (!requests) {
138148
setStore("permission", request.sessionID, [request])

packages/opencode/src/cli/cmd/tui/ui/dialog-select.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export interface DialogSelectOption<T = any> {
3737
title: string
3838
value: T
3939
description?: string
40+
search?: string
4041
footer?: JSX.Element | string
4142
category?: string
4243
categoryView?: JSX.Element
@@ -93,8 +94,8 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
9394
// users typically search by the item name, and not its category.
9495
const result = fuzzysort
9596
.go(needle, options, {
96-
keys: ["title", "category"],
97-
scoreFn: (r) => r[0].score * 2 + r[1].score,
97+
keys: ["title", "category", "search"],
98+
scoreFn: (r) => r[0].score * 2 + r[1].score + r[2].score,
9899
})
99100
.map((x) => x.obj)
100101

packages/opencode/src/config/keybinds.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const KeybindsSchema = Schema.Struct({
5252
messages_undo: keybind("<leader>u", "Undo message"),
5353
messages_redo: keybind("<leader>r", "Redo message"),
5454
messages_toggle_conceal: keybind("<leader>h", "Toggle code block concealment in messages"),
55+
permission_auto_accept_toggle: keybind("none", "Toggle auto-accept for edit permission requests"),
5556
tool_details: keybind("none", "Toggle tool details visibility"),
5657
model_list: keybind("<leader>m", "List available models"),
5758
model_cycle_recent: keybind("f2", "Next recently used model"),

packages/opencode/test/agent/agent.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ test("build agent has correct default properties", async () => {
4747
expect(build).toBeDefined()
4848
expect(build?.mode).toBe("primary")
4949
expect(build?.native).toBe(true)
50-
expect(evalPerm(build, "edit")).toBe("allow")
50+
expect(evalPerm(build, "edit")).toBe("ask")
5151
expect(evalPerm(build, "bash")).toBe("allow")
5252
},
5353
})
@@ -224,8 +224,8 @@ test("agent permission config merges with defaults", async () => {
224224
expect(build).toBeDefined()
225225
// Specific pattern is denied
226226
expect(Permission.evaluate("bash", "rm -rf *", build!.permission).action).toBe("deny")
227-
// Edit still allowed
228-
expect(evalPerm(build, "edit")).toBe("allow")
227+
// Edit still asks (default behavior)
228+
expect(evalPerm(build, "edit")).toBe("ask")
229229
},
230230
})
231231
})

0 commit comments

Comments
 (0)