Skip to content

Commit 00f40c2

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

8 files changed

Lines changed: 52 additions & 7 deletions

File tree

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/app.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ function App(props: { onSnapshot?: () => Promise<string[]> }) {
502502
{
503503
title: "Toggle MCPs",
504504
value: "mcp.list",
505+
search: "toggle mcps",
505506
category: "Agent",
506507
slash: {
507508
name: "mcps",
@@ -608,6 +609,7 @@ function App(props: { onSnapshot?: () => Promise<string[]> }) {
608609
{
609610
title: mode() === "dark" ? "Switch to light mode" : "Switch to dark mode",
610611
value: "theme.switch_mode",
612+
search: "toggle appearance",
611613
onSelect: (dialog) => {
612614
setMode(mode() === "dark" ? "light" : "dark")
613615
dialog.clear()
@@ -656,6 +658,7 @@ function App(props: { onSnapshot?: () => Promise<string[]> }) {
656658
},
657659
{
658660
title: "Toggle debug panel",
661+
search: "toggle debug",
659662
category: "System",
660663
value: "app.debug",
661664
onSelect: (dialog) => {
@@ -665,6 +668,7 @@ function App(props: { onSnapshot?: () => Promise<string[]> }) {
665668
},
666669
{
667670
title: "Toggle console",
671+
search: "toggle console",
668672
category: "System",
669673
value: "app.console",
670674
onSelect: (dialog) => {
@@ -706,6 +710,7 @@ function App(props: { onSnapshot?: () => Promise<string[]> }) {
706710
{
707711
title: terminalTitleEnabled() ? "Disable terminal title" : "Enable terminal title",
708712
value: "terminal.title.toggle",
713+
search: "toggle terminal title",
709714
keybind: "terminal_title_toggle",
710715
category: "System",
711716
onSelect: (dialog) => {
@@ -721,6 +726,7 @@ function App(props: { onSnapshot?: () => Promise<string[]> }) {
721726
{
722727
title: kv.get("animations_enabled", true) ? "Disable animations" : "Enable animations",
723728
value: "app.toggle.animations",
729+
search: "toggle animations",
724730
category: "System",
725731
onSelect: (dialog) => {
726732
kv.set("animations_enabled", !kv.get("animations_enabled", true))
@@ -751,6 +757,7 @@ function App(props: { onSnapshot?: () => Promise<string[]> }) {
751757
{
752758
title: kv.get("diff_wrap_mode", "word") === "word" ? "Disable diff wrapping" : "Enable diff wrapping",
753759
value: "app.toggle.diffwrap",
760+
search: "toggle diff wrapping",
754761
category: "System",
755762
onSelect: (dialog) => {
756763
const current = kv.get("diff_wrap_mode", "word")

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ export function Prompt(props: PromptProps) {
135135
if (!file) return
136136
return Locale.truncateMiddle(file, Math.max(12, Math.min(48, Math.floor(dimensions().width / 3))))
137137
})
138+
const [autoaccept, setAutoaccept] = kv.signal<"none" | "edit">("permission_auto_accept", "edit")
138139
const [auto, setAuto] = createSignal<AutocompleteRef>()
139140
const currentProviderLabel = createMemo(() => local.model.parsed().provider)
140141
const hasRightContent = createMemo(() => Boolean(props.right))
@@ -254,6 +255,17 @@ export function Prompt(props: PromptProps) {
254255

255256
command.register(() => {
256257
return [
258+
{
259+
title: autoaccept() === "none" ? "Enable autoedit" : "Disable autoedit",
260+
value: "permission.auto_accept.toggle",
261+
search: "toggle permissions",
262+
keybind: "permission_auto_accept_toggle",
263+
category: "Agent",
264+
onSelect: (dialog) => {
265+
setAutoaccept(() => (autoaccept() === "none" ? "edit" : "none"))
266+
dialog.clear()
267+
},
268+
},
257269
{
258270
title: "Clear prompt",
259271
value: "prompt.clear",
@@ -1282,6 +1294,11 @@ export function Prompt(props: PromptProps) {
12821294
</box>
12831295
<Show when={hasRightContent()}>
12841296
<box flexDirection="row" gap={1} alignItems="center">
1297+
<Show when={autoaccept() === "edit"}>
1298+
<text>
1299+
<span style={{ fg: theme.warning }}>autoedit</span>
1300+
</text>
1301+
</Show>
12851302
{props.right}
12861303
</box>
12871304
</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/routes/session/index.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,7 @@ export function Session() {
605605
{
606606
title: sidebarVisible() ? "Hide sidebar" : "Show sidebar",
607607
value: "session.sidebar.toggle",
608+
search: "toggle sidebar",
608609
keybind: "sidebar_toggle",
609610
category: "Session",
610611
onSelect: (dialog) => {
@@ -619,6 +620,7 @@ export function Session() {
619620
{
620621
title: conceal() ? "Disable code concealment" : "Enable code concealment",
621622
value: "session.toggle.conceal",
623+
search: "toggle code concealment",
622624
keybind: "messages_toggle_conceal",
623625
category: "Session",
624626
onSelect: (dialog) => {
@@ -629,6 +631,7 @@ export function Session() {
629631
{
630632
title: showTimestamps() ? "Hide timestamps" : "Show timestamps",
631633
value: "session.toggle.timestamps",
634+
search: "toggle timestamps",
632635
category: "Session",
633636
slash: {
634637
name: "timestamps",
@@ -642,6 +645,7 @@ export function Session() {
642645
{
643646
title: showThinking() ? "Hide thinking" : "Show thinking",
644647
value: "session.toggle.thinking",
648+
search: "toggle thinking",
645649
keybind: "display_thinking",
646650
category: "Session",
647651
slash: {
@@ -656,6 +660,7 @@ export function Session() {
656660
{
657661
title: showDetails() ? "Hide tool details" : "Show tool details",
658662
value: "session.toggle.actions",
663+
search: "toggle tool details",
659664
keybind: "tool_details",
660665
category: "Session",
661666
onSelect: (dialog) => {
@@ -664,8 +669,9 @@ export function Session() {
664669
},
665670
},
666671
{
667-
title: "Toggle session scrollbar",
672+
title: showScrollbar() ? "Hide session scrollbar" : "Show session scrollbar",
668673
value: "session.toggle.scrollbar",
674+
search: "toggle session scrollbar",
669675
keybind: "scrollbar_toggle",
670676
category: "Session",
671677
onSelect: (dialog) => {

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
@@ -62,6 +62,7 @@ const KeybindsSchema = Schema.Struct({
6262
agent_list: keybind("<leader>a", "List agents"),
6363
agent_cycle: keybind("tab", "Next agent"),
6464
agent_cycle_reverse: keybind("shift+tab", "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: 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)