Skip to content

Commit ecfcfe6

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

5 files changed

Lines changed: 35 additions & 7 deletions

File tree

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ export function Prompt(props: PromptProps) {
262262
onCleanup(() => clearInterval(timer))
263263
})
264264

265+
const [autoaccept, setAutoaccept] = kv.signal<"none" | "edit">("permission_auto_accept", "edit")
266+
265267
function promptModelWarning() {
266268
toast.show({
267269
variant: "warning",
@@ -383,6 +385,17 @@ export function Prompt(props: PromptProps) {
383385

384386
command.register(() => {
385387
return [
388+
{
389+
title: autoaccept() === "none" ? "Enable autoedit" : "Disable autoedit",
390+
value: "permission.auto_accept.toggle",
391+
search: "toggle permissions",
392+
keybind: "permission_auto_accept_toggle",
393+
category: "Agent",
394+
onSelect: (dialog) => {
395+
setAutoaccept(() => (autoaccept() === "none" ? "edit" : "none"))
396+
dialog.clear()
397+
},
398+
},
386399
{
387400
title: "Clear prompt",
388401
value: "prompt.clear",
@@ -1459,8 +1472,13 @@ export function Prompt(props: PromptProps) {
14591472
)}
14601473
</Show>
14611474
</box>
1462-
<Show when={hasRightContent()}>
1475+
<Show when={hasRightContent() || autoaccept() === "edit"}>
14631476
<box flexDirection="row" gap={1} alignItems="center">
1477+
<Show when={autoaccept() === "edit"}>
1478+
<text>
1479+
<span style={{ fg: theme.warning }}>autoedit</span>
1480+
</text>
1481+
</Show>
14641482
{props.right}
14651483
</box>
14661484
</Show>

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ 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 * as Log from "@opencode-ai/core/util/log"
3233
import { emptyConsoleState, type ConsoleState } from "@/config/console-state"
3334
import path from "path"
34-
import { useKV } from "./kv"
3535

3636
export const { use: useSync, provider: SyncProvider } = createSimpleContext({
3737
name: "Sync",
@@ -110,6 +110,7 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
110110
const project = useProject()
111111
const sdk = useSDK()
112112
const kv = useKV()
113+
const [autoaccept] = kv.signal<"none" | "edit">("permission_auto_accept", "edit")
113114

114115
const fullSyncedSessions = new Set<string>()
115116
let syncedWorkspace = project.workspace.current()
@@ -152,6 +153,13 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
152153

153154
case "permission.asked": {
154155
const request = event.properties
156+
if (autoaccept() === "edit" && request.permission === "edit") {
157+
sdk.client.permission.reply({
158+
reply: "once",
159+
requestID: request.id,
160+
})
161+
break
162+
}
155163
const requests = store.permission[request.sessionID]
156164
if (!requests) {
157165
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
@@ -38,6 +38,7 @@ export interface DialogSelectOption<T = any> {
3838
title: string
3939
value: T
4040
description?: string
41+
search?: string
4142
footer?: JSX.Element | string
4243
category?: string
4344
categoryView?: JSX.Element
@@ -94,8 +95,8 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
9495
// users typically search by the item name, and not its category.
9596
const result = fuzzysort
9697
.go(needle, options, {
97-
keys: ["title", "category"],
98-
scoreFn: (r) => r[0].score * 2 + r[1].score,
98+
keys: ["title", "category", "search"],
99+
scoreFn: (r) => r[0].score * 2 + r[1].score + r[2].score,
99100
})
100101
.map((x) => x.obj)
101102

packages/opencode/src/config/keybinds.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ const KeybindsSchema = Schema.Struct({
6161
command_list: keybind("ctrl+p", "List available commands"),
6262
agent_list: keybind("<leader>a", "List agents"),
6363
agent_cycle: keybind("tab", "Next agent"),
64-
agent_cycle_reverse: keybind("shift+tab", "Previous agent"),
64+
agent_cycle_reverse: keybind("none", "Previous agent"),
65+
permission_auto_accept_toggle: keybind("shift+tab", "Toggle auto-accept mode for permissions"),
6566
variant_cycle: keybind("ctrl+t", "Cycle model variants"),
6667
variant_list: keybind("none", "List model variants"),
6768
input_clear: keybind("ctrl+c", "Clear input field"),

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ test("agent permission config merges with defaults", async () => {
229229
expect(build).toBeDefined()
230230
// Specific pattern is denied
231231
expect(Permission.evaluate("bash", "rm -rf *", build!.permission).action).toBe("deny")
232-
// Edit still allowed
233-
expect(evalPerm(build, "edit")).toBe("allow")
232+
// Edit still asks (default behavior)
233+
expect(evalPerm(build, "edit")).toBe("ask")
234234
},
235235
})
236236
})

0 commit comments

Comments
 (0)