Skip to content

Commit a3ba740

Browse files
fix: resolve hanging permission prompts in headless mode (#3522)
Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
1 parent dc96664 commit a3ba740

File tree

1 file changed

+30
-1
lines changed
  • packages/opencode/src/cli/cmd

1 file changed

+30
-1
lines changed

packages/opencode/src/cli/cmd/run.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import { Agent } from "../../agent/agent"
1414
import { Command } from "../../command"
1515
import { SessionPrompt } from "../../session/prompt"
1616
import { EOL } from "os"
17+
import { Permission } from "@/permission"
18+
import { select } from "@clack/prompts"
1719

1820
const TOOL: Record<string, [string, string]> = {
1921
todowrite: ["Todo", UI.Style.TEXT_WARNING_BOLD],
@@ -229,7 +231,9 @@ export const RunCommand = cmd({
229231
const [tool, color] = TOOL[part.tool] ?? [part.tool, UI.Style.TEXT_INFO_BOLD]
230232
const title =
231233
part.state.title ||
232-
(Object.keys(part.state.input).length > 0 ? JSON.stringify(part.state.input) : "Unknown")
234+
(Object.keys(part.state.input).length > 0
235+
? JSON.stringify(part.state.input)
236+
: "Unknown")
233237

234238
printEvent(color, tool, title)
235239

@@ -275,6 +279,31 @@ export const RunCommand = cmd({
275279
UI.error(err)
276280
})
277281

282+
Bus.subscribe(Permission.Event.Updated, async (evt) => {
283+
const permission = evt.properties
284+
const message = `Permission required to run: ${permission.title}`
285+
286+
const result = await select({
287+
message,
288+
options: [
289+
{ value: "once", label: "Allow once" },
290+
{ value: "always", label: "Always allow" },
291+
{ value: "reject", label: "Reject" },
292+
],
293+
initialValue: "once",
294+
}).catch(() => "reject")
295+
const response = (result.toString().includes("cancel") ? "reject" : result) as
296+
| "once"
297+
| "always"
298+
| "reject"
299+
300+
Permission.respond({
301+
sessionID: session.id,
302+
permissionID: permission.id,
303+
response,
304+
})
305+
})
306+
278307
await (async () => {
279308
if (args.command) {
280309
return await SessionPrompt.command({

0 commit comments

Comments
 (0)