feat: add --yolo flag for auto-approving permissions in web/serve mode
Add a `--yolo` CLI flag to both `opencode web` and `opencode serve` commands that automatically approves all permission requests without prompting the user. This is useful for: - Headless/automated deployments - CI/CD pipelines - Development environments where interactive prompts are not desired - Remote access scenarios where the web UI handles permission decisions Implementation: - Added `yolo` boolean option to shared network options in `network.ts` - Created `applyYoloMode()` helper that sets `OPENCODE_PERMISSION` env var with all permissions set to "allow" (bash, edit, read, glob, grep, list, task, webfetch, websearch, lsp, skill, etc.) - Both `web.ts` and `serve.ts` call `applyYoloMode()` before server startup Usage: opencode web --yolo opencode serve --yolo Built exclusively with openrouter/pony-alpha and OpenCode.pull/12684/head
parent
4abf8049c9
commit
8a014113a4
|
|
@ -1,6 +1,6 @@
|
|||
import { Server } from "../../server/server"
|
||||
import { cmd } from "./cmd"
|
||||
import { withNetworkOptions, resolveNetworkOptions } from "../network"
|
||||
import { withNetworkOptions, resolveNetworkOptions, applyYoloMode } from "../network"
|
||||
import { Flag } from "../../flag/flag"
|
||||
|
||||
export const ServeCommand = cmd({
|
||||
|
|
@ -8,6 +8,7 @@ export const ServeCommand = cmd({
|
|||
builder: (yargs) => withNetworkOptions(yargs),
|
||||
describe: "starts a headless opencode server",
|
||||
handler: async (args) => {
|
||||
if (args.yolo) applyYoloMode()
|
||||
if (!Flag.OPENCODE_SERVER_PASSWORD) {
|
||||
console.log("Warning: OPENCODE_SERVER_PASSWORD is not set; server is unsecured.")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { Server } from "../../server/server"
|
||||
import { UI } from "../ui"
|
||||
import { cmd } from "./cmd"
|
||||
import { withNetworkOptions, resolveNetworkOptions } from "../network"
|
||||
import { withNetworkOptions, resolveNetworkOptions, applyYoloMode } from "../network"
|
||||
import { Flag } from "../../flag/flag"
|
||||
import open from "open"
|
||||
import { networkInterfaces } from "os"
|
||||
|
|
@ -33,6 +33,7 @@ export const WebCommand = cmd({
|
|||
builder: (yargs) => withNetworkOptions(yargs),
|
||||
describe: "start opencode server and open web interface",
|
||||
handler: async (args) => {
|
||||
if (args.yolo) applyYoloMode()
|
||||
if (!Flag.OPENCODE_SERVER_PASSWORD) {
|
||||
UI.println(UI.Style.TEXT_WARNING_BOLD + "! " + "OPENCODE_SERVER_PASSWORD is not set; server is unsecured.")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,11 @@ const options = {
|
|||
describe: "additional domains to allow for CORS",
|
||||
default: [] as string[],
|
||||
},
|
||||
yolo: {
|
||||
type: "boolean" as const,
|
||||
describe: "auto-approve all permissions (YOLO mode)",
|
||||
default: false,
|
||||
},
|
||||
}
|
||||
|
||||
export type NetworkOptions = InferredOptionTypes<typeof options>
|
||||
|
|
@ -58,3 +63,25 @@ export async function resolveNetworkOptions(args: NetworkOptions) {
|
|||
|
||||
return { hostname, port, mdns, mdnsDomain, cors }
|
||||
}
|
||||
|
||||
export function applyYoloMode() {
|
||||
process.env.OPENCODE_PERMISSION = JSON.stringify({
|
||||
bash: "allow",
|
||||
edit: "allow",
|
||||
read: { "*": "allow" },
|
||||
glob: { "*": "allow" },
|
||||
grep: { "*": "allow" },
|
||||
list: { "*": "allow" },
|
||||
task: "allow",
|
||||
external_directory: { "*": "allow" },
|
||||
todowrite: "allow",
|
||||
todoread: "allow",
|
||||
question: "allow",
|
||||
webfetch: "allow",
|
||||
websearch: "allow",
|
||||
codesearch: "allow",
|
||||
lsp: { "*": "allow" },
|
||||
doom_loop: "allow",
|
||||
skill: { "*": "allow" },
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue