Skip to content

Commit a99f638

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

4 files changed

Lines changed: 36 additions & 3 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/component/prompt/index.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ export function Prompt(props: PromptProps) {
109109
const dimensions = useTerminalDimensions()
110110
const { theme, syntax } = useTheme()
111111
const kv = useKV()
112+
const [autoaccept, setAutoaccept] = kv.signal<"none" | "edit">("permission_auto_accept", "edit")
112113
const animationsEnabled = createMemo(() => kv.get("animations_enabled", true))
113114
const list = createMemo(() => props.placeholders?.normal ?? [])
114115
const shell = createMemo(() => props.placeholders?.shell ?? [])
@@ -137,7 +138,7 @@ export function Prompt(props: PromptProps) {
137138
})
138139
const [auto, setAuto] = createSignal<AutocompleteRef>()
139140
const currentProviderLabel = createMemo(() => local.model.parsed().provider)
140-
const hasRightContent = createMemo(() => Boolean(props.right))
141+
const hasRightContent = createMemo(() => Boolean(props.right) || autoaccept() === "edit")
141142

142143
function promptModelWarning() {
143144
toast.show({
@@ -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",
@@ -1283,6 +1295,11 @@ export function Prompt(props: PromptProps) {
12831295
<Show when={hasRightContent()}>
12841296
<box flexDirection="row" gap={1} alignItems="center">
12851297
{props.right}
1298+
<Show when={autoaccept() === "edit"}>
1299+
<text>
1300+
<span style={{ fg: theme.warning }}>autoedit</span>
1301+
</text>
1302+
</Show>
12861303
</box>
12871304
</Show>
12881305
</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 * as Log from "@opencode-ai/core/util/log"
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+
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

0 commit comments

Comments
 (0)