Skip to content
Open
Show file tree
Hide file tree
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
17 changes: 16 additions & 1 deletion packages/opencode/src/cli/cmd/serve.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
import { Server } from "../../server/server"
import { cmd } from "./cmd"
import { withNetworkOptions, resolveNetworkOptions } from "../network"
import path from "path"

export const ServeCommand = cmd({
command: "serve",
builder: (yargs) => withNetworkOptions(yargs),
builder: (yargs) =>
withNetworkOptions(yargs).option("cwd", {
describe: "working directory",
type: "string",
}),
describe: "starts a headless opencode server",
handler: async (args) => {
// Resolve working directory similar to TUI command
const baseCwd = process.env.PWD ?? process.cwd()
const cwd = args.cwd ? path.resolve(baseCwd, args.cwd) : process.cwd()
try {
process.chdir(cwd)
} catch (e) {
console.error("Failed to change directory to " + cwd)
return
}

const opts = await resolveNetworkOptions(args)
const server = Server.listen(opts)
console.log(`opencode server listening on http://${server.hostname}:${server.port}`)
Expand Down
17 changes: 16 additions & 1 deletion packages/opencode/src/cli/cmd/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { cmd } from "./cmd"
import { withNetworkOptions, resolveNetworkOptions } from "../network"
import open from "open"
import { networkInterfaces } from "os"
import path from "path"

function getNetworkIPs() {
const nets = networkInterfaces()
Expand All @@ -29,9 +30,23 @@ function getNetworkIPs() {

export const WebCommand = cmd({
command: "web",
builder: (yargs) => withNetworkOptions(yargs),
builder: (yargs) =>
withNetworkOptions(yargs).option("cwd", {
describe: "working directory",
type: "string",
}),
describe: "starts a headless opencode server",
handler: async (args) => {
// Resolve working directory similar to TUI command
const baseCwd = process.env.PWD ?? process.cwd()
const cwd = args.cwd ? path.resolve(baseCwd, args.cwd) : process.cwd()
try {
process.chdir(cwd)
} catch (e) {
UI.error("Failed to change directory to " + cwd)
return
}

const opts = await resolveNetworkOptions(args)
const server = Server.listen(opts)
UI.empty()
Expand Down