diff options
| author | Ritoban Dutta <[email protected]> | 2025-10-31 02:07:41 +0530 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-10-30 15:37:41 -0500 |
| commit | a3ba740de41eb1e4825a99dc8f519e1225357e55 (patch) | |
| tree | df2d27fb5d3e1398ebf758723a1fd668a0b8c03d | |
| parent | dc96664578a3b51a72c928b906c81deaec5f9d14 (diff) | |
| download | opencode-a3ba740de41eb1e4825a99dc8f519e1225357e55.tar.gz opencode-a3ba740de41eb1e4825a99dc8f519e1225357e55.zip | |
fix: resolve hanging permission prompts in headless mode (#3522)
Co-authored-by: Aiden Cline <[email protected]>
| -rw-r--r-- | packages/opencode/src/cli/cmd/run.ts | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/packages/opencode/src/cli/cmd/run.ts b/packages/opencode/src/cli/cmd/run.ts index 7bde4a314..a979f8baa 100644 --- a/packages/opencode/src/cli/cmd/run.ts +++ b/packages/opencode/src/cli/cmd/run.ts @@ -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], @@ -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) @@ -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({ |
