7731d1235d
deploy-www / deploy (push) Has been cancelled
publish / version (push) Has been cancelled
publish / build-cli (push) Has been cancelled
publish / sign-cli-macos (push) Has been cancelled
publish / build-node-cli (map[host:blacksmith-4vcpu-ubuntu-2404 target:linux-x64]) (push) Has been cancelled
publish / build-node-cli (map[host:blacksmith-4vcpu-ubuntu-2404-arm target:linux-arm64]) (push) Has been cancelled
publish / build-node-cli (map[host:blacksmith-4vcpu-windows-2025 target:windows-arm64]) (push) Has been cancelled
publish / build-node-cli (map[host:blacksmith-4vcpu-windows-2025 target:windows-x64]) (push) Has been cancelled
publish / build-node-cli (map[host:macos-26 target:darwin-arm64]) (push) Has been cancelled
publish / sign-cli-windows (push) Has been cancelled
publish / build-electron (map[bun_install_flags:--os=darwin --cpu=arm64 host:macos-26 platform_flag:--mac --arm64 target:aarch64-apple-darwin]) (push) Has been cancelled
publish / build-electron (map[bun_install_flags:--os=darwin --cpu=x64 host:macos-26-intel platform_flag:--mac --x64 target:x86_64-apple-darwin]) (push) Has been cancelled
publish / build-electron (map[host:blacksmith-4vcpu-ubuntu-2404 platform_flag:--linux target:x86_64-unknown-linux-gnu]) (push) Has been cancelled
publish / build-electron (map[host:blacksmith-4vcpu-ubuntu-2404-arm platform_flag:--linux --arm64 target:aarch64-unknown-linux-gnu]) (push) Has been cancelled
publish / build-electron (map[host:blacksmith-4vcpu-windows-2025 platform_flag:--win target:x86_64-pc-windows-msvc]) (push) Has been cancelled
publish / build-electron (map[host:windows-2025 platform_flag:--win --arm64 target:aarch64-pc-windows-msvc]) (push) Has been cancelled
publish / publish (push) Has been cancelled
generate / generate (push) Has been cancelled
typecheck / typecheck (push) Has been cancelled
Co-authored-by: Dax Raad <d@ironbay.co>
283 lines
11 KiB
TypeScript
283 lines
11 KiB
TypeScript
import { Argument, Command, Flag } from "effect/unstable/cli"
|
|
import { Spec } from "../framework/spec"
|
|
import { GlobalFlags } from "./global-flags"
|
|
|
|
declare const OPENCODE_CLI_NAME: string | undefined
|
|
|
|
const ServerParams = {
|
|
standalone: Flag.boolean("standalone").pipe(
|
|
Flag.withDescription("Run with a private server instead of the background service"),
|
|
Flag.withDefault(false),
|
|
),
|
|
server: Flag.string("server").pipe(
|
|
Flag.withDescription("Connect to a server URL instead of the background service"),
|
|
Flag.optional,
|
|
),
|
|
}
|
|
|
|
const PermissionParams = {
|
|
auto: Flag.boolean("auto").pipe(
|
|
Flag.withDescription("Auto-approve permissions that are not explicitly denied"),
|
|
Flag.withDefault(false),
|
|
),
|
|
yolo: Flag.boolean("yolo").pipe(Flag.withDefault(false), Flag.withHidden),
|
|
dangerouslySkipPermissions: Flag.boolean("dangerously-skip-permissions").pipe(
|
|
Flag.withDefault(false),
|
|
Flag.withHidden,
|
|
),
|
|
}
|
|
|
|
const Root = Spec.make(typeof OPENCODE_CLI_NAME === "string" ? OPENCODE_CLI_NAME : "opencode", {
|
|
description: "OpenCode 2.0 preview command line interface",
|
|
params: {
|
|
...ServerParams,
|
|
...PermissionParams,
|
|
directory: Argument.string("directory").pipe(
|
|
Argument.withDescription("Directory to start OpenCode in"),
|
|
Argument.optional,
|
|
),
|
|
continue: Flag.boolean("continue").pipe(
|
|
Flag.withAlias("c"),
|
|
Flag.withDescription("Continue the last session"),
|
|
Flag.withDefault(false),
|
|
),
|
|
session: Flag.string("session").pipe(
|
|
Flag.withAlias("s"),
|
|
Flag.withDescription("Session ID to continue"),
|
|
Flag.optional,
|
|
),
|
|
prompt: Flag.string("prompt").pipe(Flag.withDescription("Prompt to use"), Flag.optional),
|
|
},
|
|
commands: [
|
|
Spec.make("acp", { description: "Start an Agent Client Protocol server" }),
|
|
Spec.make("api", {
|
|
description: "Make a request to the running server",
|
|
params: {
|
|
...ServerParams,
|
|
request: Argument.string("operation | method path").pipe(
|
|
Argument.withDescription("OpenAPI operation ID, or an HTTP method followed by a path"),
|
|
Argument.variadic({ min: 1, max: 2 }),
|
|
),
|
|
data: Flag.string("data").pipe(Flag.withAlias("d"), Flag.withDescription("Request body"), Flag.optional),
|
|
header: Flag.string("header").pipe(
|
|
Flag.withAlias("H"),
|
|
Flag.withDescription("Request header in name:value form"),
|
|
Flag.atMost(100),
|
|
),
|
|
param: Flag.keyValuePair("param").pipe(Flag.withDescription("OpenAPI path or query parameter"), Flag.optional),
|
|
},
|
|
}),
|
|
Spec.make("debug", {
|
|
description: "Debugging and troubleshooting tools",
|
|
commands: [
|
|
Spec.make("agents", { description: "List all agents" }),
|
|
Spec.make("config", { description: "List configuration sources" }),
|
|
],
|
|
}),
|
|
Spec.make("console", {
|
|
description: "Manage OpenCode Console access",
|
|
commands: [
|
|
Spec.make("login", {
|
|
description: "Log in to OpenCode Console",
|
|
params: {
|
|
url: Argument.string("url").pipe(Argument.withDescription("Console server URL"), Argument.optional),
|
|
},
|
|
}),
|
|
],
|
|
}),
|
|
Spec.make("auth", {
|
|
description: "Manage authentication",
|
|
commands: [
|
|
Spec.make("login", {
|
|
description: "Log in to a well-known authentication provider",
|
|
params: {
|
|
url: Argument.string("url").pipe(Argument.withDescription("Well-known provider URL")),
|
|
},
|
|
}),
|
|
],
|
|
}),
|
|
Spec.make("mcp", {
|
|
description: "Manage MCP (Model Context Protocol) servers",
|
|
commands: [
|
|
Spec.make("list", { description: "List configured MCP servers and their status" }),
|
|
Spec.make("add", {
|
|
description: "Add an MCP server to your configuration",
|
|
params: {
|
|
name: Argument.string("name").pipe(Argument.withDescription("Name of the MCP server")),
|
|
command: Argument.string("command").pipe(
|
|
Argument.withDescription("Command and arguments for a local server, passed after --"),
|
|
Argument.variadic({ min: 0 }),
|
|
),
|
|
url: Flag.string("url").pipe(Flag.withDescription("URL for a remote MCP server"), Flag.optional),
|
|
header: Flag.keyValuePair("header").pipe(
|
|
Flag.withDescription("HTTP header for a remote server, as name=value"),
|
|
Flag.optional,
|
|
),
|
|
env: Flag.keyValuePair("env").pipe(
|
|
Flag.withDescription("Environment variable for a local server, as name=value"),
|
|
Flag.optional,
|
|
),
|
|
global: Flag.boolean("global").pipe(
|
|
Flag.withDescription("Write to the global config instead of the project config"),
|
|
Flag.withDefault(false),
|
|
),
|
|
},
|
|
}),
|
|
Spec.make("auth", {
|
|
description: "Authenticate with an OAuth-capable remote MCP server",
|
|
params: { name: Argument.string("name").pipe(Argument.withDescription("Name of the MCP server")) },
|
|
}),
|
|
Spec.make("logout", {
|
|
description: "Remove stored OAuth credentials for an MCP server",
|
|
params: { name: Argument.string("name").pipe(Argument.withDescription("Name of the MCP server")) },
|
|
}),
|
|
],
|
|
}),
|
|
Spec.make("plugin", {
|
|
description: "Manage plugins",
|
|
commands: [Spec.make("list", { description: "List active plugins" })],
|
|
}),
|
|
Spec.make("models", {
|
|
description: "List all available models",
|
|
params: ServerParams,
|
|
}),
|
|
Spec.make("export", {
|
|
description: "Export session data as JSON",
|
|
params: {
|
|
...ServerParams,
|
|
session: Flag.string("session").pipe(
|
|
Flag.withAlias("s"),
|
|
Flag.withDescription("Session ID to export to stdout"),
|
|
Flag.optional,
|
|
),
|
|
sanitize: Flag.boolean("sanitize").pipe(
|
|
Flag.withDescription("Redact sensitive transcript and file data"),
|
|
Flag.withDefault(false),
|
|
),
|
|
},
|
|
}),
|
|
Spec.make("import", {
|
|
description: "Import session data from a JSON file or URL",
|
|
params: {
|
|
...ServerParams,
|
|
file: Argument.string("file").pipe(Argument.withDescription("JSON file or URL to import")),
|
|
directory: Flag.string("directory").pipe(
|
|
Flag.withDescription("Directory in which to import the session"),
|
|
Flag.optional,
|
|
),
|
|
},
|
|
}),
|
|
Spec.make("mini", {
|
|
description: "Start the minimal interactive interface",
|
|
params: {
|
|
...ServerParams,
|
|
continue: Flag.boolean("continue").pipe(
|
|
Flag.withAlias("c"),
|
|
Flag.withDescription("Continue the last session"),
|
|
Flag.withDefault(false),
|
|
),
|
|
session: Flag.string("session").pipe(
|
|
Flag.withAlias("s"),
|
|
Flag.withDescription("Session ID to continue"),
|
|
Flag.optional,
|
|
),
|
|
fork: Flag.boolean("fork").pipe(
|
|
Flag.withDescription("Fork the session when continuing"),
|
|
Flag.withDefault(false),
|
|
),
|
|
replay: Flag.boolean("replay").pipe(
|
|
Flag.withDescription("Restore session history on resume and resize (disable with --no-replay)"),
|
|
Flag.optional,
|
|
),
|
|
replayLimit: Flag.integer("replay-limit").pipe(
|
|
Flag.withDescription("Limit replay to the newest N messages (default: 200)"),
|
|
Flag.optional,
|
|
),
|
|
model: Flag.string("model").pipe(
|
|
Flag.withAlias("m"),
|
|
Flag.withDescription("Model to use in the format provider/model"),
|
|
Flag.optional,
|
|
),
|
|
agent: Flag.string("agent").pipe(Flag.withDescription("Agent to use"), Flag.optional),
|
|
prompt: Flag.string("prompt").pipe(Flag.withDescription("Prompt to use"), Flag.optional),
|
|
demo: Flag.boolean("demo").pipe(Flag.withDefault(false), Flag.withHidden),
|
|
},
|
|
}),
|
|
Spec.make("run", {
|
|
description: "Run OpenCode with a message",
|
|
params: {
|
|
...ServerParams,
|
|
message: Argument.string("message").pipe(
|
|
Argument.withDescription("Message to send"),
|
|
Argument.variadic({ min: 0 }),
|
|
),
|
|
continue: Flag.boolean("continue").pipe(
|
|
Flag.withAlias("c"),
|
|
Flag.withDescription("Continue the last session"),
|
|
Flag.withDefault(false),
|
|
),
|
|
session: Flag.string("session").pipe(
|
|
Flag.withAlias("s"),
|
|
Flag.withDescription("Session ID to continue"),
|
|
Flag.optional,
|
|
),
|
|
fork: Flag.boolean("fork").pipe(
|
|
Flag.withDescription("Fork the session before continuing"),
|
|
Flag.withDefault(false),
|
|
),
|
|
model: Flag.string("model").pipe(
|
|
Flag.withAlias("m"),
|
|
Flag.withDescription("Model to use in the format provider/model#variant"),
|
|
Flag.optional,
|
|
),
|
|
agent: Flag.string("agent").pipe(Flag.withDescription("Agent to use"), Flag.optional),
|
|
format: Flag.choice("format", ["default", "json"]).pipe(
|
|
Flag.withDescription("Output format"),
|
|
Flag.withDefault("default"),
|
|
),
|
|
file: Flag.string("file").pipe(
|
|
Flag.withAlias("f"),
|
|
Flag.withDescription("File to attach to the message"),
|
|
Flag.atMost(100),
|
|
),
|
|
title: Flag.string("title").pipe(Flag.withDescription("Session title"), Flag.optional),
|
|
thinking: Flag.boolean("thinking").pipe(Flag.withDescription("Show thinking blocks"), Flag.withDefault(false)),
|
|
...PermissionParams,
|
|
},
|
|
}),
|
|
Spec.make("service", {
|
|
description: "Manage the background server",
|
|
commands: [
|
|
Spec.make("start", { description: "Start the background server" }),
|
|
Spec.make("restart", { description: "Restart the background server" }),
|
|
Spec.make("status", { description: "Show background server status" }),
|
|
Spec.make("stop", { description: "Stop the background server" }),
|
|
Spec.make("get", {
|
|
description: "Get service configuration",
|
|
params: { key: Argument.string("key").pipe(Argument.optional) },
|
|
}),
|
|
Spec.make("set", {
|
|
description: "Set service configuration",
|
|
params: { key: Argument.string("key"), value: Argument.string("value") },
|
|
}),
|
|
Spec.make("unset", {
|
|
description: "Unset service configuration",
|
|
params: { key: Argument.string("key") },
|
|
}),
|
|
],
|
|
}),
|
|
Spec.make("pair", { description: "Show server pairing information" }),
|
|
Spec.make("serve", {
|
|
description: "Start the v2 API and web server",
|
|
params: {
|
|
hostname: Flag.string("hostname").pipe(Flag.optional),
|
|
port: Flag.integer("port").pipe(Flag.optional),
|
|
service: Flag.boolean("service").pipe(Flag.withDefault(false)),
|
|
stdio: Flag.boolean("stdio").pipe(Flag.withDefault(false)),
|
|
},
|
|
}),
|
|
],
|
|
})
|
|
|
|
export const Commands = { ...Root, spec: Root.spec.pipe(Command.withGlobalFlags(GlobalFlags.all)) }
|