Skip to content

Commit 4acc077

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

4 files changed

Lines changed: 41 additions & 4 deletions

File tree

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ export function Prompt(props: PromptProps) {
286286
const timer = setInterval(() => setWorkspaceCreatingDots((dots) => (dots % 3) + 1), 1000)
287287
onCleanup(() => clearInterval(timer))
288288
})
289+
const [autoaccept, setAutoaccept] = kv.signal<"none" | "edit">("permission_auto_accept", "edit")
289290

290291
function promptModelWarning() {
291292
toast.show({
@@ -406,6 +407,17 @@ export function Prompt(props: PromptProps) {
406407

407408
const promptCommands = createMemo(() =>
408409
[
410+
{
411+
title: autoaccept() === "none" ? "Enable autoedit" : "Disable autoedit",
412+
name: "permission.auto_accept.toggle",
413+
search: "toggle permissions",
414+
keybind: "permission_auto_accept_toggle",
415+
category: "Agent",
416+
run: () => {
417+
setAutoaccept(() => (autoaccept() === "none" ? "edit" : "none"))
418+
dialog.clear()
419+
},
420+
},
409421
{
410422
title: "Clear prompt",
411423
name: "prompt.clear",
@@ -1594,6 +1606,11 @@ export function Prompt(props: PromptProps) {
15941606
)}
15951607
</Show>
15961608
</box>
1609+
<Show when={autoaccept() === "edit"}>
1610+
<text>
1611+
<span style={{ fg: theme.warning }}>autoedit</span>
1612+
</text>
1613+
</Show>
15971614
<Show when={hasRightContent()}>
15981615
<box flexDirection="row" gap={1} alignItems="center">
15991616
{props.right}

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
import { aggregateFailures } from "./aggregate-failures"
3636

3737
export const { use: useSync, provider: SyncProvider } = createSimpleContext({
@@ -111,6 +111,7 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
111111
const project = useProject()
112112
const sdk = useSDK()
113113
const kv = useKV()
114+
const [autoaccept] = kv.signal<"none" | "edit">("permission_auto_accept", "edit")
114115

115116
const fullSyncedSessions = new Set<string>()
116117

@@ -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: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,8 @@ export function Session() {
654654
{
655655
title: sidebarVisible() ? "Hide sidebar" : "Show sidebar",
656656
value: "session.sidebar.toggle",
657+
search: "toggle sidebar",
658+
keybind: "sidebar_toggle",
657659
category: "Session",
658660
run: () => {
659661
batch(() => {
@@ -667,6 +669,8 @@ export function Session() {
667669
{
668670
title: conceal() ? "Disable code concealment" : "Enable code concealment",
669671
value: "session.toggle.conceal",
672+
search: "toggle code concealment",
673+
keybind: "messages_toggle_conceal" as any,
670674
category: "Session",
671675
run: () => {
672676
setConceal((prev) => !prev)
@@ -676,6 +680,7 @@ export function Session() {
676680
{
677681
title: showTimestamps() ? "Hide timestamps" : "Show timestamps",
678682
value: "session.toggle.timestamps",
683+
search: "toggle timestamps",
679684
category: "Session",
680685
slash: {
681686
name: "timestamps",
@@ -693,6 +698,8 @@ export function Session() {
693698
return "Expand thinking"
694699
})(),
695700
value: "session.toggle.thinking",
701+
search: "toggle thinking",
702+
keybind: "display_thinking",
696703
category: "Session",
697704
slash: {
698705
name: "thinking",
@@ -706,15 +713,19 @@ export function Session() {
706713
{
707714
title: showDetails() ? "Hide tool details" : "Show tool details",
708715
value: "session.toggle.actions",
716+
search: "toggle tool details",
717+
keybind: "tool_details",
709718
category: "Session",
710719
run: () => {
711720
setShowDetails((prev) => !prev)
712721
dialog.clear()
713722
},
714723
},
715724
{
716-
title: "Toggle session scrollbar",
725+
title: showScrollbar() ? "Hide session scrollbar" : "Show session scrollbar",
717726
value: "session.toggle.scrollbar",
727+
search: "toggle session scrollbar",
728+
keybind: "scrollbar_toggle",
718729
category: "Session",
719730
run: () => {
720731
setShowScrollbar((prev) => !prev)

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export interface DialogSelectOption<T = any> {
5151
title: string
5252
value: T
5353
description?: string
54+
search?: string
5455
footer?: JSX.Element | string
5556
category?: string
5657
categoryView?: JSX.Element
@@ -126,8 +127,8 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
126127
// users typically search by the item name, and not its category.
127128
const result = fuzzysort
128129
.go(needle, options, {
129-
keys: ["title", "category"],
130-
scoreFn: (r) => r[0].score * 2 + r[1].score,
130+
keys: ["title", "category", "search"],
131+
scoreFn: (r) => r[0].score * 2 + r[1].score + r[2].score,
131132
})
132133
.map((x) => x.obj)
133134

0 commit comments

Comments
 (0)