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
11 changes: 10 additions & 1 deletion packages/opencode/src/cli/cmd/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export const ServeCommand = cmd({
type: "string",
describe: "hostname to listen on",
default: "127.0.0.1",
})
.option("unix", {
type: "string",
describe: "unix socket path to bind to (overrides port/hostname)",
}),
describe: "starts a headless opencode server",
handler: async (args) => {
Expand All @@ -34,9 +38,14 @@ export const ServeCommand = cmd({
const server = Server.listen({
port,
hostname,
unix: args.unix,
})

console.log(`opencode server listening on http://${server.hostname}:${server.port}`)
if (args.unix) {
console.log(`opencode server listening on unix socket: ${args.unix}`)
} else {
console.log(`opencode server listening on http://${server.hostname}:${server.port}`)
}

await new Promise(() => {})

Expand Down
5 changes: 5 additions & 0 deletions packages/opencode/src/cli/cmd/tui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ export const TuiCommand = cmd({
type: "string",
describe: "hostname to listen on",
default: "127.0.0.1",
})
.option("unix", {
type: "string",
describe: "unix socket path to bind to (overrides port/hostname)",
}),
handler: async (args) => {
while (true) {
Expand Down Expand Up @@ -108,6 +112,7 @@ export const TuiCommand = cmd({
const server = Server.listen({
port: args.port,
hostname: args.hostname,
unix: args.unix,
})

let cmd = ["go", "run", "./main.go"]
Expand Down
17 changes: 12 additions & 5 deletions packages/opencode/src/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1235,13 +1235,20 @@ export namespace Server {
return result
}

export function listen(opts: { port: number; hostname: string }) {
const server = Bun.serve({
port: opts.port,
hostname: opts.hostname,
export function listen(opts: { port?: number; hostname?: string; unix?: string }) {
const serverOpts: any = {
idleTimeout: 0,
fetch: app().fetch,
})
}

if (opts.unix) {
serverOpts.unix = opts.unix
} else {
serverOpts.port = opts.port || 0
serverOpts.hostname = opts.hostname || "127.0.0.1"
}

const server = Bun.serve(serverOpts)
return server
}
}