mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-14 03:56:55 +03:00
fix(tui): preview always-allow patterns without extra confirmation (#47369)
This commit is contained in:
@@ -17,7 +17,7 @@ import { SimulationSemantics } from "../../simulation/semantics"
|
||||
import { PatchDiff } from "../../component/patch-diff"
|
||||
import { useToast } from "../../ui/toast"
|
||||
|
||||
type PermissionStage = "permission" | "always" | "reject"
|
||||
type PermissionStage = "permission" | "reject"
|
||||
|
||||
function EditBody(props: { file?: string; diff?: string; patch?: string }) {
|
||||
const theme = useTheme()
|
||||
@@ -141,27 +141,6 @@ export function PermissionPrompt(props: { request: PermissionRequest; directory?
|
||||
|
||||
return (
|
||||
<Switch>
|
||||
<Match when={store.stage === "always"}>
|
||||
<SessionQuestion
|
||||
title="Always allow"
|
||||
semanticLabel={`Always allow ${props.request.action}`}
|
||||
instance={props.request.id}
|
||||
body={
|
||||
<box paddingLeft={1} gap={1}>
|
||||
<For each={permissionAlwaysLines(props.request)}>
|
||||
{(line, index) => <text fg={index() === 0 ? theme.text.subdued : theme.text.default}>{line}</text>}
|
||||
</For>
|
||||
</box>
|
||||
}
|
||||
options={{ confirm: permissionOptionLabel("confirm"), cancel: permissionOptionLabel("cancel") }}
|
||||
escapeKey="cancel"
|
||||
onSelect={(option) => {
|
||||
setStore("stage", "permission")
|
||||
if (option === "cancel") return
|
||||
reply("always")
|
||||
}}
|
||||
/>
|
||||
</Match>
|
||||
<Match when={store.stage === "reject"}>
|
||||
<RejectPrompt
|
||||
action={props.request.action}
|
||||
@@ -186,7 +165,7 @@ export function PermissionPrompt(props: { request: PermissionRequest; directory?
|
||||
},
|
||||
pathFormatter.format,
|
||||
)
|
||||
const presentationBody =
|
||||
const presentationBody = () =>
|
||||
props.request.action === "edit" ? (
|
||||
<EditBody file={current.file} diff={current.diff} patch={current.patch} />
|
||||
) : props.request.action === "external_directory" ? (
|
||||
@@ -241,7 +220,15 @@ export function PermissionPrompt(props: { request: PermissionRequest; directory?
|
||||
semanticLabel={permissionSemanticLabel(props.request.action, current.title)}
|
||||
instance={props.request.id}
|
||||
header={header()}
|
||||
body={presentationBody}
|
||||
body={(option) => (
|
||||
<Show when={option === "always"} fallback={presentationBody()}>
|
||||
<box paddingLeft={1} gap={1}>
|
||||
<For each={permissionAlwaysLines(props.request)}>
|
||||
{(line, index) => <text fg={index() === 0 ? theme.text.subdued : theme.text.default}>{line}</text>}
|
||||
</For>
|
||||
</box>
|
||||
</Show>
|
||||
)}
|
||||
options={
|
||||
props.request.save?.length
|
||||
? {
|
||||
@@ -255,7 +242,7 @@ export function PermissionPrompt(props: { request: PermissionRequest; directory?
|
||||
fullscreen
|
||||
onSelect={(option) => {
|
||||
if (option === "always") {
|
||||
setStore("stage", "always")
|
||||
reply("always")
|
||||
return
|
||||
}
|
||||
if (option === "reject") {
|
||||
@@ -425,7 +412,7 @@ export function SessionQuestion<const T extends Record<string, string>>(props: {
|
||||
group?: string
|
||||
choicesLabel?: string
|
||||
header?: JSX.Element
|
||||
body: JSX.Element
|
||||
body: JSX.Element | ((option: keyof T) => JSX.Element)
|
||||
options: T
|
||||
escapeKey?: keyof T
|
||||
fullscreen?: boolean
|
||||
@@ -549,7 +536,7 @@ export function SessionQuestion<const T extends Record<string, string>>(props: {
|
||||
{props.header}
|
||||
</box>
|
||||
</Show>
|
||||
{props.body}
|
||||
{typeof props.body === "function" ? props.body(store.selected) : props.body}
|
||||
</box>
|
||||
<box
|
||||
flexDirection={narrow() ? "column" : "row"}
|
||||
|
||||
Reference in New Issue
Block a user