Apply PR #12633: feat(tui): add auto-accept mode for permission requests
commit
41372c8e52
|
|
@ -375,6 +375,11 @@ export const RunCommand = cmd({
|
||||||
action: "deny",
|
action: "deny",
|
||||||
pattern: "*",
|
pattern: "*",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
permission: "edit",
|
||||||
|
action: "allow",
|
||||||
|
pattern: "*",
|
||||||
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
function title() {
|
function title() {
|
||||||
|
|
|
||||||
|
|
@ -569,6 +569,7 @@ function App(props: { onSnapshot?: () => Promise<string[]> }) {
|
||||||
{
|
{
|
||||||
title: "Toggle MCPs",
|
title: "Toggle MCPs",
|
||||||
value: "mcp.list",
|
value: "mcp.list",
|
||||||
|
search: "toggle mcps",
|
||||||
category: "Agent",
|
category: "Agent",
|
||||||
slash: {
|
slash: {
|
||||||
name: "mcps",
|
name: "mcps",
|
||||||
|
|
@ -673,8 +674,9 @@ function App(props: { onSnapshot?: () => Promise<string[]> }) {
|
||||||
category: "System",
|
category: "System",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "Toggle theme mode",
|
title: mode() === "dark" ? "Light mode" : "Dark mode",
|
||||||
value: "theme.switch_mode",
|
value: "theme.switch_mode",
|
||||||
|
search: "toggle appearance",
|
||||||
onSelect: (dialog) => {
|
onSelect: (dialog) => {
|
||||||
setMode(mode() === "dark" ? "light" : "dark")
|
setMode(mode() === "dark" ? "light" : "dark")
|
||||||
dialog.clear()
|
dialog.clear()
|
||||||
|
|
@ -723,6 +725,7 @@ function App(props: { onSnapshot?: () => Promise<string[]> }) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "Toggle debug panel",
|
title: "Toggle debug panel",
|
||||||
|
search: "toggle debug",
|
||||||
category: "System",
|
category: "System",
|
||||||
value: "app.debug",
|
value: "app.debug",
|
||||||
onSelect: (dialog) => {
|
onSelect: (dialog) => {
|
||||||
|
|
@ -732,6 +735,7 @@ function App(props: { onSnapshot?: () => Promise<string[]> }) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "Toggle console",
|
title: "Toggle console",
|
||||||
|
search: "toggle console",
|
||||||
category: "System",
|
category: "System",
|
||||||
value: "app.console",
|
value: "app.console",
|
||||||
onSelect: (dialog) => {
|
onSelect: (dialog) => {
|
||||||
|
|
@ -773,6 +777,7 @@ function App(props: { onSnapshot?: () => Promise<string[]> }) {
|
||||||
{
|
{
|
||||||
title: terminalTitleEnabled() ? "Disable terminal title" : "Enable terminal title",
|
title: terminalTitleEnabled() ? "Disable terminal title" : "Enable terminal title",
|
||||||
value: "terminal.title.toggle",
|
value: "terminal.title.toggle",
|
||||||
|
search: "toggle terminal title",
|
||||||
keybind: "terminal_title_toggle",
|
keybind: "terminal_title_toggle",
|
||||||
category: "System",
|
category: "System",
|
||||||
onSelect: (dialog) => {
|
onSelect: (dialog) => {
|
||||||
|
|
@ -788,6 +793,7 @@ function App(props: { onSnapshot?: () => Promise<string[]> }) {
|
||||||
{
|
{
|
||||||
title: kv.get("animations_enabled", true) ? "Disable animations" : "Enable animations",
|
title: kv.get("animations_enabled", true) ? "Disable animations" : "Enable animations",
|
||||||
value: "app.toggle.animations",
|
value: "app.toggle.animations",
|
||||||
|
search: "toggle animations",
|
||||||
category: "System",
|
category: "System",
|
||||||
onSelect: (dialog) => {
|
onSelect: (dialog) => {
|
||||||
kv.set("animations_enabled", !kv.get("animations_enabled", true))
|
kv.set("animations_enabled", !kv.get("animations_enabled", true))
|
||||||
|
|
@ -797,6 +803,7 @@ function App(props: { onSnapshot?: () => Promise<string[]> }) {
|
||||||
{
|
{
|
||||||
title: kv.get("diff_wrap_mode", "word") === "word" ? "Disable diff wrapping" : "Enable diff wrapping",
|
title: kv.get("diff_wrap_mode", "word") === "word" ? "Disable diff wrapping" : "Enable diff wrapping",
|
||||||
value: "app.toggle.diffwrap",
|
value: "app.toggle.diffwrap",
|
||||||
|
search: "toggle diff wrapping",
|
||||||
category: "System",
|
category: "System",
|
||||||
onSelect: (dialog) => {
|
onSelect: (dialog) => {
|
||||||
const current = kv.get("diff_wrap_mode", "word")
|
const current = kv.get("diff_wrap_mode", "word")
|
||||||
|
|
|
||||||
|
|
@ -97,6 +97,7 @@ export function Prompt(props: PromptProps) {
|
||||||
const [auto, setAuto] = createSignal<AutocompleteRef>()
|
const [auto, setAuto] = createSignal<AutocompleteRef>()
|
||||||
const currentProviderLabel = createMemo(() => local.model.parsed().provider)
|
const currentProviderLabel = createMemo(() => local.model.parsed().provider)
|
||||||
const hasRightContent = createMemo(() => Boolean(props.right))
|
const hasRightContent = createMemo(() => Boolean(props.right))
|
||||||
|
const [autoaccept, setAutoaccept] = kv.signal<"none" | "edit">("permission_auto_accept", "edit")
|
||||||
|
|
||||||
function promptModelWarning() {
|
function promptModelWarning() {
|
||||||
toast.show({
|
toast.show({
|
||||||
|
|
@ -211,6 +212,17 @@ export function Prompt(props: PromptProps) {
|
||||||
|
|
||||||
command.register(() => {
|
command.register(() => {
|
||||||
return [
|
return [
|
||||||
|
{
|
||||||
|
title: autoaccept() === "none" ? "Enable autoedit" : "Disable autoedit",
|
||||||
|
value: "permission.auto_accept.toggle",
|
||||||
|
search: "toggle permissions",
|
||||||
|
keybind: "permission_auto_accept_toggle",
|
||||||
|
category: "Agent",
|
||||||
|
onSelect: (dialog) => {
|
||||||
|
setAutoaccept(() => (autoaccept() === "none" ? "edit" : "none"))
|
||||||
|
dialog.clear()
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: "Clear prompt",
|
title: "Clear prompt",
|
||||||
value: "prompt.clear",
|
value: "prompt.clear",
|
||||||
|
|
@ -1109,11 +1121,14 @@ export function Prompt(props: PromptProps) {
|
||||||
</box>
|
</box>
|
||||||
</Show>
|
</Show>
|
||||||
</box>
|
</box>
|
||||||
<Show when={hasRightContent()}>
|
<box flexDirection="row" gap={1} alignItems="center">
|
||||||
<box flexDirection="row" gap={1} alignItems="center">
|
<Show when={autoaccept() === "edit"}>
|
||||||
{props.right}
|
<text>
|
||||||
</box>
|
<span style={{ fg: theme.warning }}>autoedit</span>
|
||||||
</Show>
|
</text>
|
||||||
|
</Show>
|
||||||
|
<Show when={hasRightContent()}>{props.right}</Show>
|
||||||
|
</box>
|
||||||
</box>
|
</box>
|
||||||
</box>
|
</box>
|
||||||
</box>
|
</box>
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ import { createSimpleContext } from "./helper"
|
||||||
import type { Snapshot } from "@/snapshot"
|
import type { Snapshot } from "@/snapshot"
|
||||||
import { useExit } from "./exit"
|
import { useExit } from "./exit"
|
||||||
import { useArgs } from "./args"
|
import { useArgs } from "./args"
|
||||||
|
import { useKV } from "./kv"
|
||||||
import { batch, onMount } from "solid-js"
|
import { batch, onMount } from "solid-js"
|
||||||
import { Log } from "@/util/log"
|
import { Log } from "@/util/log"
|
||||||
import type { Path } from "@opencode-ai/sdk"
|
import type { Path } from "@opencode-ai/sdk"
|
||||||
|
|
@ -109,6 +110,8 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
|
||||||
})
|
})
|
||||||
|
|
||||||
const sdk = useSDK()
|
const sdk = useSDK()
|
||||||
|
const kv = useKV()
|
||||||
|
const [autoaccept] = kv.signal<"none" | "edit">("permission_auto_accept", "edit")
|
||||||
|
|
||||||
async function syncWorkspaces() {
|
async function syncWorkspaces() {
|
||||||
const result = await sdk.client.experimental.workspace.list().catch(() => undefined)
|
const result = await sdk.client.experimental.workspace.list().catch(() => undefined)
|
||||||
|
|
@ -139,6 +142,13 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
|
||||||
|
|
||||||
case "permission.asked": {
|
case "permission.asked": {
|
||||||
const request = event.properties
|
const request = event.properties
|
||||||
|
if (autoaccept() === "edit" && request.permission === "edit") {
|
||||||
|
sdk.client.permission.reply({
|
||||||
|
reply: "once",
|
||||||
|
requestID: request.id,
|
||||||
|
})
|
||||||
|
break
|
||||||
|
}
|
||||||
const requests = store.permission[request.sessionID]
|
const requests = store.permission[request.sessionID]
|
||||||
if (!requests) {
|
if (!requests) {
|
||||||
setStore("permission", request.sessionID, [request])
|
setStore("permission", request.sessionID, [request])
|
||||||
|
|
@ -463,6 +473,7 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
|
||||||
get ready() {
|
get ready() {
|
||||||
return store.status !== "loading"
|
return store.status !== "loading"
|
||||||
},
|
},
|
||||||
|
|
||||||
session: {
|
session: {
|
||||||
get(sessionID: string) {
|
get(sessionID: string) {
|
||||||
const match = Binary.search(store.session, sessionID, (s) => s.id)
|
const match = Binary.search(store.session, sessionID, (s) => s.id)
|
||||||
|
|
|
||||||
|
|
@ -554,6 +554,7 @@ export function Session() {
|
||||||
{
|
{
|
||||||
title: sidebarVisible() ? "Hide sidebar" : "Show sidebar",
|
title: sidebarVisible() ? "Hide sidebar" : "Show sidebar",
|
||||||
value: "session.sidebar.toggle",
|
value: "session.sidebar.toggle",
|
||||||
|
search: "toggle sidebar",
|
||||||
keybind: "sidebar_toggle",
|
keybind: "sidebar_toggle",
|
||||||
category: "Session",
|
category: "Session",
|
||||||
onSelect: (dialog) => {
|
onSelect: (dialog) => {
|
||||||
|
|
@ -568,6 +569,7 @@ export function Session() {
|
||||||
{
|
{
|
||||||
title: conceal() ? "Disable code concealment" : "Enable code concealment",
|
title: conceal() ? "Disable code concealment" : "Enable code concealment",
|
||||||
value: "session.toggle.conceal",
|
value: "session.toggle.conceal",
|
||||||
|
search: "toggle code concealment",
|
||||||
keybind: "messages_toggle_conceal" as any,
|
keybind: "messages_toggle_conceal" as any,
|
||||||
category: "Session",
|
category: "Session",
|
||||||
onSelect: (dialog) => {
|
onSelect: (dialog) => {
|
||||||
|
|
@ -578,6 +580,7 @@ export function Session() {
|
||||||
{
|
{
|
||||||
title: showTimestamps() ? "Hide timestamps" : "Show timestamps",
|
title: showTimestamps() ? "Hide timestamps" : "Show timestamps",
|
||||||
value: "session.toggle.timestamps",
|
value: "session.toggle.timestamps",
|
||||||
|
search: "toggle timestamps",
|
||||||
category: "Session",
|
category: "Session",
|
||||||
slash: {
|
slash: {
|
||||||
name: "timestamps",
|
name: "timestamps",
|
||||||
|
|
@ -591,6 +594,7 @@ export function Session() {
|
||||||
{
|
{
|
||||||
title: showThinking() ? "Hide thinking" : "Show thinking",
|
title: showThinking() ? "Hide thinking" : "Show thinking",
|
||||||
value: "session.toggle.thinking",
|
value: "session.toggle.thinking",
|
||||||
|
search: "toggle thinking",
|
||||||
keybind: "display_thinking",
|
keybind: "display_thinking",
|
||||||
category: "Session",
|
category: "Session",
|
||||||
slash: {
|
slash: {
|
||||||
|
|
@ -605,6 +609,7 @@ export function Session() {
|
||||||
{
|
{
|
||||||
title: showDetails() ? "Hide tool details" : "Show tool details",
|
title: showDetails() ? "Hide tool details" : "Show tool details",
|
||||||
value: "session.toggle.actions",
|
value: "session.toggle.actions",
|
||||||
|
search: "toggle tool details",
|
||||||
keybind: "tool_details",
|
keybind: "tool_details",
|
||||||
category: "Session",
|
category: "Session",
|
||||||
onSelect: (dialog) => {
|
onSelect: (dialog) => {
|
||||||
|
|
@ -613,8 +618,9 @@ export function Session() {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "Toggle session scrollbar",
|
title: showScrollbar() ? "Hide session scrollbar" : "Show session scrollbar",
|
||||||
value: "session.toggle.scrollbar",
|
value: "session.toggle.scrollbar",
|
||||||
|
search: "toggle session scrollbar",
|
||||||
keybind: "scrollbar_toggle",
|
keybind: "scrollbar_toggle",
|
||||||
category: "Session",
|
category: "Session",
|
||||||
onSelect: (dialog) => {
|
onSelect: (dialog) => {
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ export interface DialogSelectOption<T = any> {
|
||||||
title: string
|
title: string
|
||||||
value: T
|
value: T
|
||||||
description?: string
|
description?: string
|
||||||
|
search?: string
|
||||||
footer?: JSX.Element | string
|
footer?: JSX.Element | string
|
||||||
category?: string
|
category?: string
|
||||||
categoryView?: JSX.Element
|
categoryView?: JSX.Element
|
||||||
|
|
@ -91,8 +92,8 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
|
||||||
// users typically search by the item name, and not its category.
|
// users typically search by the item name, and not its category.
|
||||||
const result = fuzzysort
|
const result = fuzzysort
|
||||||
.go(needle, options, {
|
.go(needle, options, {
|
||||||
keys: ["title", "category"],
|
keys: ["title", "category", "search"],
|
||||||
scoreFn: (r) => r[0].score * 2 + r[1].score,
|
scoreFn: (r) => r[0].score * 2 + r[1].score + r[2].score,
|
||||||
})
|
})
|
||||||
.map((x) => x.obj)
|
.map((x) => x.obj)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -667,7 +667,12 @@ export namespace Config {
|
||||||
command_list: z.string().optional().default("ctrl+p").describe("List available commands"),
|
command_list: z.string().optional().default("ctrl+p").describe("List available commands"),
|
||||||
agent_list: z.string().optional().default("<leader>a").describe("List agents"),
|
agent_list: z.string().optional().default("<leader>a").describe("List agents"),
|
||||||
agent_cycle: z.string().optional().default("tab").describe("Next agent"),
|
agent_cycle: z.string().optional().default("tab").describe("Next agent"),
|
||||||
agent_cycle_reverse: z.string().optional().default("shift+tab").describe("Previous agent"),
|
agent_cycle_reverse: z.string().optional().default("none").describe("Previous agent"),
|
||||||
|
permission_auto_accept_toggle: z
|
||||||
|
.string()
|
||||||
|
.optional()
|
||||||
|
.default("shift+tab")
|
||||||
|
.describe("Toggle auto-accept mode for permissions"),
|
||||||
variant_cycle: z.string().optional().default("ctrl+t").describe("Cycle model variants"),
|
variant_cycle: z.string().optional().default("ctrl+t").describe("Cycle model variants"),
|
||||||
variant_list: z.string().optional().default("none").describe("List model variants"),
|
variant_list: z.string().optional().default("none").describe("List model variants"),
|
||||||
input_clear: z.string().optional().default("ctrl+c").describe("Clear input field"),
|
input_clear: z.string().optional().default("ctrl+c").describe("Clear input field"),
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ test("build agent has correct default properties", async () => {
|
||||||
expect(build).toBeDefined()
|
expect(build).toBeDefined()
|
||||||
expect(build?.mode).toBe("primary")
|
expect(build?.mode).toBe("primary")
|
||||||
expect(build?.native).toBe(true)
|
expect(build?.native).toBe(true)
|
||||||
expect(evalPerm(build, "edit")).toBe("allow")
|
expect(evalPerm(build, "edit")).toBe("ask")
|
||||||
expect(evalPerm(build, "bash")).toBe("allow")
|
expect(evalPerm(build, "bash")).toBe("allow")
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
@ -219,8 +219,8 @@ test("agent permission config merges with defaults", async () => {
|
||||||
expect(build).toBeDefined()
|
expect(build).toBeDefined()
|
||||||
// Specific pattern is denied
|
// Specific pattern is denied
|
||||||
expect(Permission.evaluate("bash", "rm -rf *", build!.permission).action).toBe("deny")
|
expect(Permission.evaluate("bash", "rm -rf *", build!.permission).action).toBe("deny")
|
||||||
// Edit still allowed
|
// Edit still asks (default behavior)
|
||||||
expect(evalPerm(build, "edit")).toBe("allow")
|
expect(evalPerm(build, "edit")).toBe("ask")
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue