Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion packages/opencode/src/cli/cmd/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { Agent } from "../../agent/agent"
import { Command } from "../../command"
import { SessionPrompt } from "../../session/prompt"
import { EOL } from "os"
import { Permission } from "@/permission"
import { select } from "@clack/prompts"

const TOOL: Record<string, [string, string]> = {
todowrite: ["Todo", UI.Style.TEXT_WARNING_BOLD],
Expand Down Expand Up @@ -229,7 +231,9 @@ export const RunCommand = cmd({
const [tool, color] = TOOL[part.tool] ?? [part.tool, UI.Style.TEXT_INFO_BOLD]
const title =
part.state.title ||
(Object.keys(part.state.input).length > 0 ? JSON.stringify(part.state.input) : "Unknown")
(Object.keys(part.state.input).length > 0
? JSON.stringify(part.state.input)
: "Unknown")

printEvent(color, tool, title)

Expand Down Expand Up @@ -275,6 +279,31 @@ export const RunCommand = cmd({
UI.error(err)
})

Bus.subscribe(Permission.Event.Updated, async (evt) => {
const permission = evt.properties
const message = `Permission required to run: ${permission.title}`

const result = await select({
message,
options: [
{ value: "once", label: "Allow once" },
{ value: "always", label: "Always allow" },
{ value: "reject", label: "Reject" },
],
initialValue: "once",
}).catch(() => "reject")
const response = (result.toString().includes("cancel") ? "reject" : result) as
| "once"
| "always"
| "reject"

Permission.respond({
sessionID: session.id,
permissionID: permission.id,
response,
})
})

await (async () => {
if (args.command) {
return await SessionPrompt.command({
Expand Down